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

url: https://tecadmin.net/install-mongodb-on-ubuntu/


MongoDB is a full 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 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 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 updatesudo 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.servicesudo 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 MongoDB service.

sudo systemctl stop mongod.servicesudo systemctl restart mongod.service

How to Work with MongoDB – Read this tutorial

Step 4 – Verify MongoDB Installation

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

mongod --version

Output:

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 MongoDB server.

Create and Drop database in Mongodb

Enable authentication in Mongodb

Shell script to backup Mongodb

Backup and restore database in Mongodb

Conclusion

In this tutorial, you have learned to install MongoDB database server on Ubuntu system.

你可能感兴趣的:(How to Install MongoDB 4.4 on Ubuntu 18.04 & 16.04 via PPA)