Databases

How to Install MongoDB 4.4 on Ubuntu 20.04

This is a guide to install MongoDB 4.4 on Ubuntu 20.04 server.

This article installs MongoDB 4.4 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.

MongoDB, also known as Mongo, is an open-source document database used in many modern web applications. It’s classified as a NoSQL database because it doesn’t rely on a traditional table-based relational database structure.

Install MongoDB 4.4 on Ubuntu 20.04 server.

Prerequisites
  • Dedicated server or VPS running Ubuntu 20.04.
  • Root access or normal user with administrative privileges.
Step 1 – Keep the server up to date

# apt update -y

# apt upgrade -y

Step 2 – Import the public key

We need to import the public key used by the package management system. We can import it using following command:

# wget -qO – https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add –

Step 3 – Create a repo file

Create the list file /etc/apt/sources.list.d/mongodb-4-4.list for your version of Ubuntu. We can create the list file using following command:

# echo “deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-4-4.list

Step 4 – Update the local package database

Next, we need to update the local package database. It will refer the file we have created earlier to install MongoDB 4.4.

# apt update -y

Step 5 – Install MongoDB 4.4

Now, install MongoDB 4.4 using following command:

# apt install mongodb-org -y

Step 6 – Start and enable the MongoDB service

# systemctl start mongod

# systemctl enable mongod

Step 7 – Verify that the database is operational

You can further verify that the database is operational by connecting to the database server and executing a diagnostic command.

# mongo –eval ‘db.runCommand({ connectionStatus: 1 })’

Output:

MongoDB shell version v4.4.1
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“0873452a-ae50-4eb4-9d11-53e538f199e7”) }
MongoDB server version: 4.4.1
{
“authInfo” : {
“authenticatedUsers” : [ ],
“authenticatedUserRoles” : [ ] },
“ok” : 1
}

That’s it.

We have successfully install MongoDB 4.4 on Ubuntu 20.04.

Related Articles