Skip to main content
Skip table of contents

How to Install MongoDB on Ubuntu 16.04 Instance

MongoDB is a free and open-source NoSQL document database.

We will begin with importing MongoDB public key and adding MongoDB repositories.

CODE
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 

After adding public key, we must create a list file for MongoDB and reload the local package database by typing: 

CODE
$ echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
$ sudo apt update

You can install latest stable version of MongoDB by typing: 

CODE
$ sudo apt install -y mongo-org

After installation you must create systemd service file for only Ubuntu 16.04. 

Create a new file at /lib/systemd/system/mongod.service with following lines:

CODE
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual

[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target

After creating systemd service file you must start the mongod service

CODE
$ sudo systemctl start mongod.service

Connecting MongoDB shell just typing :

CODE
$ mongo

If you are getting an error like this: 

CODE
Failed global initialization: BadValue Invalid or no user locale set.  
Please ensure LANG and/or LC_* environment variables are set correctly. 
locale::facet::_S_create_c_locale name not valid

You must edit /etc/default/locale file like this 

CODE
LANG=en_US.UTF-8
LANGUAGE=en_US
LC_ALL=en_US.UTF-8 

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.