10

DISCOUNT

REGISTER NOW

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.

$ 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: 

$ 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: 

$ 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:

[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

$ sudo systemctl start mongod.service

Connecting MongoDB shell just typing :

$ mongo

If you are getting an error like this: 

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 

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

 

 

 

 

 

Have more questions? Submit a request
Powered by Zendesk