MongoDB

How to Install MongoDB Community Edition 6.0.5 on Ubuntu 22.04?

MongoDB Community Edition is a free and powerful Non-Relational database to store BSON documents. It can be installed on Ubuntu which is an open-source operating system to support modern applications. It offers numerous useful features, such as load balancing, availability, and real time analytics. This post will discuss the procedure to install MongoDB Community’s latest edition 6.0.5 on Ubuntu 22.04.

How to Install MongoDB Community Edition 6.0.5 on Ubuntu 22.04?

MongoDB Community Edition is an open-source documents-oriented database. In Ubuntu 22.04, follow these steps to install the MongoDB Community Edition 6.0.5:

Step 1: Import the MongoDB GPG key

In Ubuntu 22.04, right-click and select the option “Open in Terminal”:

The gnupg package is already installed in Ubuntu. In case it is not installed then  install the key management system by executing the given below command:

sudo apt-get install gnupg

Output

The GnuPG is successfully installed in Ubuntu 22.04.

To import the MongoDB key from the official website, use the command provided below:

curl -fsSL https://pgp.mongodb.com/server-6.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg \
--dearmor

Output

The MongoDB GPG key was imported successfully.

Step 2: Create a List File to Import the MongoDB Repository

After importing the MongoDB GPG key, run this command to create a file “mongodb-org-6.0.list” in “source.list.d” directory to import the MongoDB repository:

echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

Output

The output returned a message after adding the MongoDB repositories in Ubuntu 22.04.

Step 3: Update the Package Lists

The next step is to update the package lists after adding the key and repository of Ubuntu 22.04 by running the below command:

sudo apt-get update

Output

The package lists updated successfully in Ubuntu.

Step 4: Install the 6.0.5 Edition in MongoDB Community

The user can download the latest as well as any specific edition of the MongoDB Community database in Ubuntu 22.04.

Install the MongoDB Latest Version

Install the latest version of MongoDB by utilizing this command:

sudo apt-get install -y mongodb-org

Output

The installation will take some time.

Wait for the completion of the latest edition of the MongoDB community in Ubuntu 22.04:

Install the Specific Version of MongoDB

However, to install any specific edition of the MongoDB community database. Execute the command provided below:

sudo apt-get install -y mongodb-org=6.0.5 mongodb-org-database=6.0.5 mongodb-org-server=6.0.5 mongodb-org-mongos=6.0.5 mongodb-org-tools=6.0.5

To download any specific edition, the user must list all required MongoDB product names and edition numbers.

Output

The output showed that the specified edition was installed successfully.

Step 5: Verify MongoDB Installation

To verify whether the MongoDB Community Edition 6.0.5 is installed successfully or not, run the given command:

mongosh --eval 'db.runCommand({ ping: 1 })'

Output

The output sent a ping request to the MongoDB server and displayed a response from it. In case of any error, start the MongoDB services.

Step 6: Manage MongoDB Service

Once the MongoDB Community Edition is installed, the user can start, stop, and enable the MongoDB services automatically.

To see the status of the MongoDB service, run this command:

sudo systemctl status mongod

Output

It returned the status of the MongoDB server as active.

Stop the MongoDB Service

Sometimes, the user needs to stop the MongoDB service to perform some configurations. To stop the service, run the command given below:

sudo systemctl stop mongod

After stopping the service, execute the “status” command to see the MongoDB service.

Output

The MongoDB server stopped successfully. 

Start the MongoDB Service

To start the MongoDB service, the user can run this command:

sudo systemctl start mongod

After starting the service, run the “status” command to see the MongoDB service:

Output

The MongoDB server started successfully.

Restart the MongoDB Service

Similarly, to restart the MongoDB server, run this command:

sudo systemctl restart mongod

Output

The MongoDB server will restart successfully.

Step 7: Enable the MongoDB Service to Startup at Boot Automatically

The “enable” command can be utilized to start the MongoDB server automatically after every boot-up:

sudo systemctl enable mongod

Output

This command starts the MongoDB server after every boot-up automatically.

Conclusion

To install the latest or specific edition of the MongoDB Community database, add the GPG key and repository of MongoDB in Ubuntu 22.04. After the installation, verify it by sending a ping request to the MongoDB server to see its response. The user can manage the services of MongoDB server. This post demonstrated the process of installing MongoDB Community Edition 6.0.5 on Ubuntu 22.04.

About the author

Nimrah Ch

I’m a technical writer with a Bachelor's in Software Engineering and Certification in Cyber Security. Through my research and writing, I strive to provide readers with in-depth, informative articles that can help them make informed decisions about their technological needs.