Introduction:
MongoDB stands out as a popular and powerful NoSQL database system. Here we will learn how to Install MongoDB on Ubuntu, If you’re using Ubuntu as your operating system, installing MongoDB can be a seamless process that will have you managing your data like a pro in no time.
Understanding the Benefits of MongoDB:
Before we dive into the installation process, let’s explore why MongoDB is an excellent choice for your database needs. MongoDB offers flexibility, scalability, and high-performance data storage capabilities. Its document-oriented nature allows for easy organization and retrieval of data, making it ideal for both small and large-scale applications.
Preparing Your Ubuntu System:
To ensure a smooth installation, there are a few prerequisites that need to be met. We will walk you through the necessary steps, including updating your system, adding the MongoDB repository, and importing the MongoDB GPG key.
Install MongoDB on Ubuntu:
As of the current date, the default Ubuntu repositories offer MongoDB version 6.0, while we are going to install a stable release, MongoDB 4.4, is not available in those repositories.
In order to acquire the latest version of MongoDB, it is necessary to add MongoDB’s dedicated package repository to your APT sources. By doing so, you can install MongoDB-org, a meta-package that always directs you to the most up-to-date MongoDB release.
To begin, execute the following command to import the public GPG key for the latest stable version of MongoDB. If you plan to install a MongoDB version different from 4.4, make sure to modify the URL section of this command to match the desired version you wish to install.
curl -fsSL https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
BashThe data stored at the provided URL is retrieved by cURL and displayed in the system’s output. In the given example, cURL outputs the content of the GPG key file, which is then passed through a pipe to the command “sudo apt-key add –“, effectively adding the GPG key to the list of trusted keys.
The output should return OK;
OK
On your server, there are two locations where APT searches for online package sources for downloading and installing: the sources. List file and the sources.list.d directory. The sources, list file contains active APT data sources, with each source listed on a separate line, prioritizing the most preferred sources. The sources.list.d directory allows you to add individual source entries as separate files.
Execute the following command to create a file named MongoDB-org-4.4.list in the sources.list.d directory. This file will contain only one line: “deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse”.
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
Once you have executed the command, proceed to update the local package index on your server. This update is essential for APT to be aware of the location where the mongodb-org package can be found.
sudo apt update
After completing the aforementioned steps, you are now ready to proceed with the installation of MongoDB.
sudo apt install mongodb-org
When prompted, press ‘Y’ and then ‘ENTER’ to confirm your intention to install the package.
Once the command finishes executing, MongoDB will be successfully installed on your system. However, it is not yet ready for use. The next step involves starting MongoDB and verifying its functionality to ensure it is working correctly.
Starting the MongoDB:
sudo systemctl start mongod.service
Next, you can check the status of the service. It’s important to note that you don’t need to include “.service” in the service file definition when using the systemctl command. systemctl will automatically append this suffix to the argument you provide if it is not already present. Therefore, it is not necessary to explicitly include it.
sudo systemctl status mongod
Executing this command will provide output similar to the following, confirming that the service is active and operational:
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2020-10-06 15:08:09 UTC; 6s ago
Docs: https://docs.mongodb.org/manual
Main PID: 13429 (mongod)
CGroup: /system.slice/mongod.service
└─13429 /usr/bin/mongod --config /etc/mongod.conf
Once you have verified that the service is running correctly, proceed to enable the MongoDB service to automatically start up during boot:
sudo systemctl enable mongod
Managing the MongoDB Service:
If the server is already running, you have the option to restart it by executing the following command:
sudo systemctl restart mongod
Conclusion:
By following this comprehensive guide, you will be able to install MongoDB on Ubuntu like a pro, simplifying your database setup and taking advantage of MongoDB’s remarkable features
Whether you’re a developer, system administrator, or someone looking to expand their knowledge in database management, this tutorial will equip you with the necessary skills to get started with MongoDB on Ubuntu. Embrace the power of this versatile database system and unlock new possibilities for your projects or business.
Like Install MongoDB on Ubuntu, You can check the post for Postgresql
Official installation – Here