Installing MongoDB on Ubuntu is straightforward. Here’s a step-by-step guide for installing MongoDB Community Edition on an Ubuntu system.

Step 1: Import the MongoDB Public Key

First, import the MongoDB public GPG key used to sign the packages:

bash
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-6.0.gpg

Step 2: Create the List File for MongoDB

Next, create a list file for MongoDB. Replace 6.0 with the desired version if needed:

bash
echo "deb [signed-by=/usr/share/keyrings/mongodb-6.0.gpg] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

Step 3: Update the Package Database

Update your local package database:

bash
sudo apt update

Step 4: Install MongoDB

Now, install MongoDB:

bash
sudo apt install -y mongodb-org

Step 5: Start MongoDB

Start the MongoDB service:

bash
sudo systemctl start mongod

Step 6: Enable MongoDB to Start on Boot

To ensure MongoDB starts on boot, run:

bash
sudo systemctl enable mongod

Step 7: Verify the Installation

You can check the status of MongoDB to confirm that it is running:

bash
sudo systemctl status mongod

Step 8: Access the MongoDB Shell

To access the MongoDB shell, run:

bash
mongosh

Additional Configuration (Optional)

  • Firewall: If you have a firewall running, you may need to allow traffic on MongoDB’s default port (27017).
  • Configuration File: The configuration file is located at /etc/mongod.conf, and you can modify it according to your needs.

Conclusion

You should now have MongoDB installed and running on your Ubuntu system. Let me know if you have any questions or need further assistance!

Sign In

Sign Up