How to install MongoDB 3.4 in Linux Mint 18 (Ubuntu 16.04)

Install Mongodb in Linux Mint 18 and Ubuntu

MongoDB is an open-source non-relational database. It is a document-oriented database designed for scalability and flexibility. Programmers find MongoDB easy for getting started as it’s data resembles to JSON and it’s command shell supports Javascript, which is one of the primary language for many developers. It’s getting more popular these days. You can check the Google Trends for MongoDB

Let’s find out how to install the latest MongoDB ( so far the latest version is 3.4) in Linux Mint ( Ubuntu 16.04). MongoDB doesn’t support 32 bit system architecture. So, we’ll cover only 64 bit Linux system here. Let’s get started.

Step 1: Open the Command-line terminal and import the public GPG key. Just run the following commands. Copy and paste ( note – it’s one line of code, not separate lines ) these commands in the terminal.

sudo apt-key adv --keyserver hkp:// --recv 0C49F3730359A14518585931BC711F9BA15703C6

Step 2: Next, we’ll create the “/etc/apt/sources.list.d/mongodb-org-3.4.list” list file ( note – it’s one line of code, not separate lines…so copy it all ).

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

Step 3: Run the system update

sudo apt-get update

Step 4: Finally, install the latest stable version of MongoDB.

sudo apt-get install -y mongodb-org

The above command will install the mongodb-org, mongodb-org-server, mongodb-org-mongos, mongodb-org-shell and mongodb-org-tools.

Step 5: After installation, create a directory with name “data” and sub-directory with name “db” inside you home directory. Otherwise, you may get problem with starting the MongoDB.

sudo mkdir -p /data/db/

Step 6: Give the directory “/data” enough permission

sudo chmod -R 775 /data/

Step 7: Create a configuration file with name “mongodb.service” to setup unit file.

sudo touch /etc/systemd/system/mongodb.service

Step 8: Open the above created file with a text editor of your choice. I prefer nano command line text editor.

sudo nano /etc/systemd/system/mongodb.service

Step 9 : Paste the following line of codes inside the editor and save this file.

Description=High-performance, schema-free document-oriented database

ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf


Save the above file use “Ctrl+o” key. Then exit the “nano” editor using key – “Ctrl+x“.

Step 10: Finally, you can start the MongoDB server. Paste the following command.

sudo systemctl start mongodb

Step 11: You can check the running status of MongoDB server with the following command.

sudo systemctl status mongodb

Leave a Reply

Your email address will not be published. Required fields are marked *