Install MongoDB on Linux — Using *.tgz tarballs — Ubuntu / Debian

Fiko Borizqy
3 min readOct 11, 2018

I will show you how to install MongoDB on linux step by step, in this tutorial I’m using Ubuntu 18.04 distro. Okay, let’s get started.

Step 1: Download MongoDB

Before you install MongoDB on your linux desktop or server, course you need to have the MongoDB master that you can download it from MongoDB official Website here: https://www.mongodb.com/download-center/v2/community

Choose the community version -> choose your operating system -> download.

Step 2: Installing Prerequisites

Next we need to have:

  • libcurl3 / libcurl4
  • openssl

So, just install them by command below:

#> sudo apt install libcurl3 openssl

or for libcurl 4:

#> sudo apt install libcurl4 openssl

you can use apt or apt-get for this operation, both of them are correct.

Step 3: Extract the MongoDB

Next you need to extract MongoDB that you just downloaded it from the website using terminal and command tar, go to the directory where you just put the master file: (in my case, it is: /home/fiko/Downloads/Programs)

#> cd /home/fiko/Downloads/Programs
cd /home/fiko/Downloads/Programs

And then execute tar command:

#> tar -zxvf mongodb-linux-*-4.0.3.tgz
tar -zxvf mongodb-linux-*-4.0.3.tgz

Next, you can do whatever you want to make sure you can access it easly. In my case, I rename the directory name onto mongodb:

And move it to /home/fiko/Applications: (you don’t need to do it if you won’t, I do it to make me easly access it.)

Step 4: Adding Binaries to the Path

Make sure your bin directory of MongoDB registered on PATH, so you can easily access it from any directory via terminal / command line.

Add this to your~/.bashrc file at the end of file: (change the directory to your directory where you installed it.)

#> export PATH=~/Applications/mongodb/bin:$PATH

Step 5: Setting up MongoDB Configuration

(optional) This is an optional step, But we recommend you to do it. We need to set the configuration of MongoDB. Create a file name mongod.conf in /etc/* directory:

#> sudo touch /etc/mongod.conf; sudo nano /etc/mongod.conf

Then paste this this code:

Step 6: Adding Service to System

(Optional) (Recommended) Next, create new file in /lib/systemd/system/* with the name mongod.service. Or you may copy this command:

#> sudo touch /lib/systemd/system/mongod.service; sudo nano /lib/systemd/system/mongod.service

And paste this to the file:

Step 7: Enable Service

After you registered the service, next you need to enable it, so mongodb will automatically started when you turn on the PC. Enable it by this command:

#> sudo systemctl enable mongod.service

Step 8: Start the MongoDB

Final step of this installation is to start the mongodb and voila, your MongoDB is ready. Start by this command:

#> sudo systemctl start mongod.service

— Completed—

Finish… please leave your comments if you got some trouble.

--

--

Fiko Borizqy

I wrote these tutorials for myself in future when I forget for the next steps.