Looking to install MongoDB on your Ubuntu, Debian, or Fedora system? You’ve come to the right place. MongoDB, a highly popular NoSQL database, offers scalability, high performance, and flexible storage capabilities. And with our step-by-step guide, you’ll have it up and running in no time.
Installing MongoDB on Ubuntu
MongoDB installation on Ubuntu is a straightforward process. By following our comprehensive tutorial, you’ll be able to add the official MongoDB repository, update the system, and install the latest version with just a few simple commands.
To begin, open the terminal on your Ubuntu system and first ensure that your system is updated. This step is crucial to avoid any compatibility issues during the installation process. Use the following command to update your system:
sudo apt update && sudo apt upgrade -y
Once your system is updated, you can proceed to add the official MongoDB repository. This repository provides the most up-to-date version of MongoDB. Run the following command to import the MongoDB GPG key:
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
Next, add the MongoDB repository to the sources list by running the following command:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
After adding the repository, update the package list again to include the MongoDB packages:
sudo apt update
Now, you are ready to install MongoDB. Run the following command to install the latest stable version:
sudo apt install mongodb-org
Once the installation is complete, MongoDB will be automatically started. You can verify the status of the MongoDB service by running:
sudo systemctl status mongod
And that’s it! MongoDB is now successfully installed on your Ubuntu system. You can start using it by connecting to the MongoDB shell using the following command:
mongo
Installing MongoDB on Debian
Installing MongoDB on Debian is similar to the process on Ubuntu. Our tutorial provides detailed instructions to ensure a smooth installation process.
Begin by opening the terminal on your Debian system and updating it using the following command:
sudo apt update && sudo apt upgrade -y
After updating the system, you can proceed to import the MongoDB GPG key by running the following command:
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
Next, add the MongoDB repository to the sources list by running the following command:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
Once the repository is added, update the package list to include the MongoDB packages:
sudo apt update
Now, you are ready to install MongoDB on Debian. Run the following command to install the latest version:
sudo apt install mongodb-org
After the installation is complete, MongoDB will be automatically started. You can verify the status of the MongoDB service by running:
sudo systemctl status mongod
That’s it! MongoDB is now successfully installed on your Debian system. You can connect to the MongoDB shell using the following command:
mongo
Installing MongoDB on Fedora
If you’re using Fedora, don’t worry – we’ve got you covered too. Our guide includes detailed steps for installing MongoDB on Fedora, ensuring a smooth installation process.
Start by opening the terminal on your Fedora system and update it using the following command:
sudo dnf update
After updating the system, you can proceed to import the MongoDB GPG key by running the following command:
sudo rpm --import https://www.mongodb.org/static/pgp/server-5.0.asc
Next, create a new repository file for MongoDB using the following command:
sudo nano /etc/yum.repos.d/mongodb-org-5.0.repo
In the file, paste the following repository configuration for MongoDB:
[mongodb-org-5.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/5.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc
Save the file and exit the text editor. Now, you can proceed with the MongoDB installation on Fedora by running the following command:
sudo dnf install -y mongodb-org
Once the installation is complete, MongoDB will be automatically started. You can verify the status of the MongoDB service by running:
sudo systemctl status mongod
Great! MongoDB is now successfully installed on your Fedora system. To connect to the MongoDB shell, use the following command:
mongo
Verifying the Installation
After installing MongoDB on your Ubuntu, Debian, or Fedora system, it’s essential to verify the installation to ensure everything is working correctly.
To verify the installation, open the terminal and run the following command:
mongo –version
This command will display the installed MongoDB version, confirming that MongoDB is successfully installed on your system.
Troubleshooting Common Installation Issues
In some cases, you may encounter issues during the MongoDB installation process. Here are a few common problems and their solutions:
- Connection timeout: If the installation process takes too long and eventually times out, make sure you have a stable internet connection. You can also try using a different network or updating your DNS settings.
- Dependency errors: If you encounter dependency errors during the installation, ensure that you have all the required dependencies installed on your system. You can try resolving the dependencies manually or using package management tools to install missing packages.
- Permission denied: If you receive a “Permission denied” error during the installation, make sure you are running the installation commands with root privileges or using the sudo command.
If you encounter any other issues during the MongoDB installation, refer to the official MongoDB documentation or seek help from the MongoDB community.
Conclusion
In this comprehensive guide, we have walked you through the process of installing MongoDB on Ubuntu, Debian, and Fedora systems. By following our step-by-step instructions, you can easily add the official MongoDB repository, update your system, and install MongoDB with ease.
Remember to verify the installation to ensure everything is working correctly. If you encounter any issues, refer to the troubleshooting section or seek help from the MongoDB community. With MongoDB successfully installed, you can now take advantage of its scalability, high performance, and flexible storage capabilities for your projects. Happy coding!

Nishant Verma is a senior web developer who love to share his knowledge about Linux, SysAdmin, and more other web handlers. Currently, he loves to write as content contributor for ServoNode.