In this article, I will be demonstrating how to install MongoDB Community Edition 5.0 on Ubuntu. If you are on an older version of Ubuntu, I would suggest upgrading your OS or updating it simply from the apt-get update command so this will open a good way to get the latest version of MongoDB without any errors.
MongoDB saves data in an unstructured format and MySQL saved data in a structured format. MongoDB is an open-source NoSQL database management program.
MongoDB stores data in JSON-like documents with flexible fields that can change from document to document and data structures that can evolve over time.
The document model corresponds to the objects in your application code, allowing you to work with data more easily.
Ad hoc searches, indexing, and real-time aggregation are all useful tools for accessing and analyzing data.
Because MongoDB is a distributed database at its heart, it comes with built-in high availability, horizontal scaling, and geographic distribution.
Steps to Install MongoDB Community Edition
MongoDB is free to use. Versions released prior to October 16, 2018 are published under the AGPL. All versions released after October/16 /2018, including patch fixes for prior versions, are published under the Server Side Public License (SSPL) v1.
Step 1
Update your Ubuntu OS first with root privileges. Update might take some time if you never run it for a long time.
# sudo apt-get update
Step 2
Install required GnuPG libraries.
# sudo apt-get install gnupg
Step 3
Once the system is updated, I will recommend rebooting first after updates are completed and running this command to import MongoDB GPG public key.
# sudo wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
Step 4
Create /etc/apt/sources.list.d/mongodb-org-5.0.list. I am adding this by using the touch command, you can create this file using your favorite editor.
# sudo cd /etc/apt/sources.list.d/ # sudo touch mongodb-org-5.0.list
Now add the following repo by the echo 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
Step 5
Finally, update the system after adding the repo and installing MongoDB.
# sudo apt-get update # sudo apt-get install -y mongodb-org
Step 6
In this step, we will learn how can we start, stop and enable MongoDB.
Start MongoDB | # sudo systemctl start mongod |
Start failed MongoDB service | # sudo systemctl daemon-reload |
To check MongoDB status | # sudo systemctl status mongod |
Enable MongoDB on system startup | # sudo systemctl enable mongod |
Stop running MongoDB | # sudo systemctl stop mongod |
Restart MongoDB | # sudo systemctl restart mongod |
The data directory for MongoDB will be var/lib/mongodb and the log directory /var/log/mongodb after installatiion and the config file location will be /etc/mongod.conf.
Steps to Uninstall MongoDB
If you want to completely uninstall MongoDB then follow these steps. This process will completely remove MongoDB from your system and will not be reversible. My recommendation is to take a proper backup before starting the removal process.
Step 1
Stop the MongoDB
# sudo systemctl stop mongod
Step 2
Purge all the packages.
# sudo apt-get purge mongodb-org*
Step 3
Remove all the directories and reboot the machine.
# sudo rm -r /var/log/mongodb # sudo rm -r /var/lib/mongodb
Once the system is rebooted, you will not find MongoDB. To verify and check the status by “sudo systemctl status mongod” you will not get any output of the command that means MongoDB is no longer available on your machine.
Also Read : How to do youtube keyword research
Also Read : Build your own file sharing Website
Video Tutorial
That’s all..In this article, we have covered how to install and uninstall the MongoDB community edition on Ubuntu 20.04 – 22.04 along with the video tutorial. I have presented this tutorial with very simple steps and tried to make visitors to understand easily. If you have any query then you can reach me anytime by contacting me on mail id.
3 thoughts on “Install MongoDB community edition on Ubuntu 20.04-22.04”
Still having a problem with this
mongodb-org-mongos : Depends: libssl1.1 (>= 1.1.1) but 1.1.0g-2ubuntu4 is to be installed
mongodb-org-server : Depends: libssl1.1 (>= 1.1.1) but 1.1.0g-2ubuntu4 is to be installed
Try to install on Ubuntu 20.04, 22.04 comes up with issues…
interesant