How to Install MongoDB 4.4 on Ubuntu 18.04 & 16.04 via PPA

How to Install MongoDB 4.4 on Ubuntu 18.04 & 16.04 via PPA

 

How to Install MongoDB 4.4 on Ubuntu 18.04 & 16.04 via PPA


MongoDB is a fully flexible index support and rich queries database. MongoDB is a NoSQL database. MongoDB provides large media storage with GridFS. Click here for more details about this version of MongoDB.

This tutorial will help you to install MongoDB 4.4 community release on Ubuntu 20.04 LTS (Focal), 18.04 LTS (Bionic), and 16.04 LTS (Xenial) systems.

Step 1 – Setup Apt Repository

First of all, import the GPK key for the MongoDB apt repository on your system using the following command. This is required to test packages before installation

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 656408E390CFB1F5

Lets add MongoDB APT repository url in /etc/apt/sources.list.d/mongodb.list.

Ubuntu 18.04 LTS:
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb.list
Ubuntu 16.04 LTS:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb.list

Step 2 – Install MongoDB on Ubuntu

After adding the required APT repositories, use the following commands to install MongoDB on your systems. It will also install all dependent packages required for MongoDB.

sudo apt update
sudo apt install mongodb-org

If you want to install any specific version of MongoDB, define the version number as below

sudo apt install mongodb-org=4.4.1 mongodb-org-server=4.4.1 mongodb-org-shell=4.4.1 mongodb-org-mongos=4.4.1 mongodb-org-tools=4.4.1

Step 3 – Manage MongoDB Service

After installation, MongoDB will start automatically. To start or stop MongoDB uses init script. Below are the example commands to do.

sudo systemctl enable mongod.service
sudo systemctl start mongod.service

Once the service started, check the status by running command:

sudo systemctl status mongod.service


Use the following commands to stop or restart the MongoDB service.

sudo systemctl stop mongod.service
sudo systemctl restart mongod.service
  • How to Work with MongoDB – Read this tutorial

Step 4 – Verify MongoDB Installation

Finally, use the below command to check the installed MongoDB version on your system.

mongod --version 

Output:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

db version v4.4.1
Build Info: {
    "version": "4.4.1",
    "gitVersion": "ad91a93a5a31e175f5cbf8c69561e788bbc55ce1",
    "openSSLVersion": "OpenSSL 1.1.1  11 Sep 2018",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu1804",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

Also, connect MongoDB using the command line and execute some test commands for checking proper working.

mongo 

> use mydb;

> db.colors.insert({ "id": 100, "color": "Pink"})
> db.colors.insert({ "id": 101, "color": "Purple"})

> db.colors.find()

  { "_id" : ObjectId("5f75a76194d0a08201f26f25"), "id" : 100, "color" : "Pink" }
  { "_id" : ObjectId("5f75a7d594d0a08201f26f26"), "id" : 101, "color" : "Purple" }

More Useful tutorials

Here is the list of useful tutorials for the MongoDB server.

Reactions

Post a Comment

0 Comments

close