18 C
Texas

How To Install MongoDB On Ubuntu 20.04

Today we are going to learn that how to install MongoDB on Ubuntu 20.04. MongoDB is open-source used in different advanced web applications in order to manage the data in Database. Here we’ll go through with some steps that help us to install MongoDB on

Step 1: Update Your System

First of all, as usual we do, update your system to have the latest updates installed before installing any new package. So, hit the below command.

sudo apt update && sudo apt upgrade -y

Once the update done, reboot your system.

- Advertisement -
sudo reboot

Step 2: Install MongoDB On Ubuntu 20.04

As the Ubuntu Official repository doesn’t have the latest version of the MongoDB, so in order to install the latest version, we’ve to install it manually. Currently the latest stable releases of MongoDB is 4.4, so we’ll install it on our system. Simply follow the below steps for an easy and optimal installation.

Now, to import the GPG key hit the below command.

sabi@Ubuntu20:~$ wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
[sudo] password for sabi:
OK

You’ll get the “Ok” message as output if it is successfull. If you face any error retry adding the key or hit the below command to install gnupg (for gnupg error).

sudo apt-get install gnupg

Once it is installed, hit the following command to import the GPG key.

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

Step 3: Create A List File For MongoDB Package

Create the list file in the /etc/apt/sources.list.d/ directory for Ubuntu 20.04.

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-org-4.4.list

And then update the system again.

sudo apt update

Step 4: Install MongoDB

Finally hit the below command to install the MongoDB 4.4 on your Ubuntu system.

sudo apt install -y mongodb-org

Step 5: Start & Enable MongoDB Services

After the installation process, start and enable the MongoDB services to run at the startup.

To start the MongoDB, hit below command.

sudo systemctl start mongod

And enable the MongoDB to start on boot type the following command in your terminal.

sudo systemctl enalbe mongod

ARestart the MongoDB services by

sudo systemctl restart mongod

Check the current status of MongoDB by typing

sabi@Ubuntu20:~$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor prese>
Active: active (running) since Thu 2020-10-29 13:59:54 PKT; 56s ago
Docs: https://docs.mongodb.org/manual
Main PID: 38663 (mongod)
Memory: 160.6M
CGroup: /system.slice/mongod.service
└─38663 /usr/bin/mongod --config /etc/mongod.conf
اکتوبر 29 13:59:54 Ubuntu20 systemd[1]: Started MongoDB Database Server.
lines 1-10/10 (END)

Stop the MongoDB with the help of below command

sudo systemctl stop mongod

To disable the MongoDB on startup, type the following command in your terminal.

sudo systemctl disable mongod

So, this is how you can install MongoDB on Ubuntu 20.04

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article