mongodb logo

MongoDB. How to install mongodb on Ubuntu 16.04

Maybe you need a MongoDB server on your system linux, in this post I will be enumerate the steps for install MongoDB on ubuntu version 16.04 that at now is the LTS version.

The first step is add the public key, you need write the following command into terminal

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

Now you need add the path for MongoDB into resources list, write into terminal the following:

echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

The following will be reload package database, write the following

sudo apt-get update

Install MongoDB

sudo apt-get install -y mongodb-org

The parameter -y is for agree all questions, also you can execute without it.

Now you can execute mongodb, you just write the command:

sudo service mongod start

If you need stop the server, then you write:

sudo service mongod stop

Remember that the configuration now is only for use in local mode, if you need connect from other pc to the server then you need modify the configuration file.

The configuration is at /etc/mongod.conf

sudo nano /etc/mongod.conf

if you open the file with nano, then edit the following line:

bindIp: 127.0.0.1

Replace the line with:

bindIp: 0.0.0.0

Now you need restart the server:

sudo service mongod restart

Also in this file you can see some configurations like:

dbPath: /var/lib/mongodb

This is path where the server will save the databases, maybe you like change this route for example for saving databases into ssd disk, that is more efficient.

With these simple steps you can execute a mongo server for a tests, production and other things, well, remember that if it is to production maybe you need more configurations and optimization in your server.

If you need connected to your server, you can use Robo 3T, this a very good client also is multi platform, you can use with Windows, Linux and Mac.

Leave a Reply