DEV Community

Sagar Jethi
Sagar Jethi

Posted on • Updated on

How to install and configure mongodb on ubuntu 18.04

Introduction

MongoDB is opensource NoSQL(document) database and document database designed for ease of development. It provides Rich Query Language, High Availability, Horizontal Scalability, Support for Multiple Storage Engines.
More check: official intriduction

Install MongoDB

The following is stepped to install MongoDB Community Edition. This step by step guideline which you can follow

step 1. Import the public key used by the PMS(package management system)

The Ubuntu package management tools ensure package consistency and authenticity by verifying that they are signed with GPG keys. The following command will import the MongoDB public GPG key.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

step 2. Create a list file for MongoDB.

Create a source list file for MongoDB

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

step 3 Reload local Ubuntu package database.

sudo apt-get update

step 4 Install the MongoDB package

Install the latest version of MongoDB.

sudo apt-get install -y mongodb-org

Install a specific release of MongoDB.

sudo apt-get install -y mongodb-org=4.0.10 mongodb-org-server=4.0.10 mongodb-org-shell=4.0.10 mongodb-org-mongos=4.0.10 mongodb-org-tools=4.0.10

For help with troubleshooting if errors encountered then check troubleshooting

Configure and Run MongoDB
te
The following step by step instructions can excute after download MongoDB and not the unofficial MongoDB package provided by Ubuntu.

Step 1:Start MongoDB.
Follow command start mongodb

sudo service mongod start

Step 2 Verify that MongoDB has started successfully

sudo systemctl status mongod
Output
mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: 
   Active: active (running) since Fri 2019-07-19 16:50:52 IST; 15min ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 30977 (mongod)
   CGroup: /system.slice/mongod.service
           └─30977 /usr/bin/mongod --config /etc/mongod.conf

you enable automatically starting MongoDB when the system starts. it is upto you

sudo systemctl enable mongod

Step 3 Stop MongoDB.
By following command stop mongod

sudo service mongod stop

Step 4 Restart MongoDB.
The following command to restart mongod:

sudo service mongod restart

Step 5 Begin using MongoDB.

mongo

Discussion (0)