1. Home
  2. Cloud and Servers
  3. Virtual Servers (VPS)
  4. Installing MongoDB on Ubuntu 18.04 LTS

Installing MongoDB on Ubuntu 18.04 LTS

MongoDB is a multiplatform document database. It is sorted as NoSQL database and contrary traditional relationship databases using tables it uses documents similar to JSON (MongoDB format is called BSON) and dynamic database schemes that allow creating and integrating data for application simple and fast. It is an open-source software published under GNU Affero General Public License and Apache licenses.

Database MongoDB was originally developed by company 10gen (now MongoDB Inc.) in 2007 as a component to planned PaaS product. In 2009 the project became open-source. MongoDB is the most popular NoSQL database system. Language controls are available for Apache license. MongoDB Inc. offers proprietary licenses for MongoDB.

guide describes installation of MongoDB Community Edition in version 4.2 from official repository and testing functionality after installation.

Try out the performance of the premium VPS

Its better to try that than to hear about it – try out the professional Virtual server from Active24 for production usage for free.
Uncompromising dedicated performance, snapshots for free, SSD for all your data.
More atactive24.cz/servery (only available for CZ and SK markets)


Guide for installing MongoDB

Hint: Before you use this guide, we would recommend to have a knowledge of installing packages on the server and editing configuration via console to one of the editors.

1. Add GPG key to the repository

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

2. Add MongoDB 4.2 repository

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

3. Update repositories and install updates of packages

sudo apt update 
sudo apt upgrade 

4. Install packages MongoDB

sudo apt-get install -y mongodb-org

Management of MongoDB

Running server

sudo service mongod start

Check if the MongoDB is running

sudo service mongod status

MongoDB is installed on localhost and port 27017, which can be check via command:

netstat -nlp|grep 27017

Stopping server

sudo service mongod stop

Restart server

sudo service mongod restart

Configuration of access to MongoDB

Running MongoDB shell

$ mongo

Switching to database admin

> use admin

Creating user admin with root rights

Exit shell with command exit

Open file/lib/systemd/system/mongod.service in the text editor and locate a line:

ExecStart=/usr/bin/mongod --config /etc/mongod.conf

Edit it to

ExecStart=/usr/bin/mongod --auth --config /etc/mongod.conf

and restart systemd and MongoDB server

sudo systemctl daemon-reload
sudo service mongod restart

Now you can connect via username and password

mongo -u admin -p admin123456 --authenticationDatabase admin
Updated on January 3, 2025

Was this article helpful?

Related Articles