MongoDB – Installation on RedHat 9
Step 1: Configure the MongoDB Repository
/etc/yum.repos.d/mongodb-org-7.0.repo using your preferred text editor (like vi or nano), or by using the cat command as shown below. This example uses version 7.0; you can check the MongoDB repositories for the latest version.cat <<EOF | sudo tee /etc/yum.repos.d/mongodb-org-7.0.repo [mongodb-org-7.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/9/mongodb-org/7.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://pgp.mongodb.com/server-7.0.asc EOF Step 2: Install MongoDB Packages
Install the latest stable version of MongoDB:
sudo dnf install -y mongodb-org Step 3: Start and Enable the MongoDB Service
Start the service and enable it to run on boot:
sudo systemctl start mongod sudo systemctl enable mongod # Verify status: sudo systemctl status mongod Step 4: Configure the Firewall (Optional)
If needed, open port 27017 to allow remote access:
sudo firewall-cmd --permanent --add-port=27017/tcp sudo firewall-cmd --reload Step 5: Begin Using MongoDB
Launch the shell to connect to your local instance:
mongosh