Mar 13, 2017 • 2 min read

Installing MongoDB 3.4 & above in Ubuntu 16+

This is a high time for NoSQL Databases with rapidly increasing data every second. By the way let me remind you that NoSQL means Not Only SQL, it doesn’t means No SQL. We’ll talk about installation of MongoDB in this article.

If you have Ubuntu installed, it already ships with an older version of MongoDB, which is version 2.6. So few days ago I was trying to install MongoDB 3.4 in my Ubuntu OS, I searched the internet on the ways to install it.

The simplest way was to use the this command :

sudo apt-get install mongodb

Problem with the above command

After the installation was complete, I tried the command

mongo --version

It was showing me v2.6, I think lot of people faced/facing this problem, if you’re one of them then stay tuned.

After that, I tried the different methods. None of them worked for me.

Last Night

Finally last night I was adamant to upgrade the MongoDB suit to version 3.4. Here are the steps that paved my way to successful installation of MongoDB 3.4 :

Remove the previous versions installed using this command :

sudo apt-get purge mongodb\*

Download the .tgz file of you choice depending on the version of OS. Go to MongoDB Download Center

After you downloaded the package, extract it using the command :

tar -xvzf name_of_package

Rename the folder just made after extraction of the package to mongodb. Command is this :

mv name_of_package mongodb

Move the folder ‘mongodb’ inside the ‘/bin’ folder in root directory using the command:

sudo mv mongodb /bin/mongodb

At this point, you need to add the mongodb binaries in the PATH variable so that they can be executed from anywhere.

There are two ways to do this and I am using the less popular way to keep things easy. What you have to do is that copy the files inside mongodb/bin to usr/local/bin

Use this command:

sudo cp /bin/mongodb/bin/\* /usr/local/bin/

Now make a data directory for MongoDB to store the data (Whatever you store in the Database will be stored here).Run this command:

# creating nested directory
sudo mkdir -p /data/db

Give read/write permissions to the data folder using this command:

sudo chmod -R o+rw /data/db

It’s Done

Now you can run mongo shell. Check the version of MongoDB using the command:

mongo --version


Run mongod before running mongo


When you restart, there is no need to run the mongodb service, the OS automatically starts that.

Hope you find the above instructions helpful. You can mention issues, suggestions in comments below.

Post by: Ashok Dey Fullstack JavaScript engineer, crafting scalable backends!