How to Install MongoDB on Linux ?

·

1 min read

Table of contents

No heading

No headings in the article.

Run the above commands to install MongoDB on Linux.

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

If Respond after this command is not ok then -

Install gnupg and its required libraries using the following command:

sudo apt-get install gnupg

Once installed, retry importing the key:

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

Now create the /etc/apt/sources.list.d/mongodb-org-6.0.list file for Ubuntu 20.04 (Focal):

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

Run the following command to reload the local package database:

sudo apt-get update

But MongoDB has no official build for ubuntu 22.04 at the moment.

Ubuntu 22.04 has upgraded libssl to 3 and does not propose libssl1.1

For that run the following commands

echo "deb http://security.ubuntu.com/ubuntu focal-security main" | sudo tee /etc/apt/sources.list.d/focal-security.list
sudo apt-get update
sudo apt-get install libssl1.1

To install the latest stable version, issue the following

sudo apt-get install -y mongodb-org

Now we are done with installation.

You can run MongoDB using the above command

sudo systemctl start mongod