MongoDB is a NoSQL database server available for Most of the latest operating systems. Use one of the following tutorials to install MongoDB on your system.
Follow below tutorials for the installation of MongoDB
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 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 below commands to stop or restart MongoDB service.
$ sudo systemctl stop mongod.service
$ sudo systemctl restart mongod.service
Step 4 – Verify MongoDB Installation
Finally, use the below command to check installed MongoDB version on your system.
$ mongod --version