Installing MongoDB 3.4 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

The problem with the above command:

After the installation was complete, I tried the command mongo --version and it was showing me v2.6, I think lots of people faced/facing this problem, if you’re one of them then stay tuned. Then after that,  I tried the different methods. None of them worked for me.

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 and MongoDB 3.4. Here is the link for .tgz file for Ubuntu 16.04 mongodb-3.4. Go to the MongoDb Download center here.

    Now choose the package  for your system

  • 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. 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.
    Run this command : sudo mkdir -p  /data/db
  • Give read/write permissions to the data folder using this command :
    sudo chmod -R o+rw /data/db
  • All done. Note :  Run mongod before running mongo
    mongod
  • Now you can run mongo shell. Check the version of MongoDB using the command :
    mongo --version
    Note : 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.

Leave a comment