Hostwinds Tutorials

Search results for:

Table of Contents

How To Install MongoDB on CentOS
How To Install MongoDB on Debian

How To Install MongoDB on Linux

Tags: Linux 

How To Install MongoDB on CentOS
How To Install MongoDB on Debian

A database is a great and easy way to store information for your site or application. One of the most common database engines you may hear about is MySQL. While this is a common solution and viable, some may choose to use MongoDB.

MongoDB is similar in that it provides an easy-to-use database. However, the data is stored. Differently, that data is also accessed. MongoDB mostly works through API calls. This allows MongoDB to be used with various programming languages for the database easily.

Here we'll show you how to get MongoDB installed and set up on a Linux server. The installation steps may differ on the distribution of Linux you're using but should be fairly similar.

These guides will go through the steps on how to install MongoDB version 3.6. Though with other versions, it's a little similar.

How To Install MongoDB on CentOS

The steps to install MongoDB on CentOS are similar to those of Fedora and other RHELinux operating systems. For that, you'll want to follow these steps.

Login to your server using SSH.

Once logged in, you'll want to add the most recent repository for MongoDB so that Linux knows where to install MongoDB from. To do this, you'll want to navigate to the /etc/yum.repos.d/  folder. You can do that with the cd command like this,

cd /etc/yum.repos.d

This will bring you to the repository directory. Here, you'll want to create a file called mongodb-org-3.6.repo and input some specific contents. You can do this with the nano command or your favorite text editor to edit the file.

nano mongodb-org-3.6.repo

After you have brought the new file open for editing, you'll want to type in the following:

name=MongoDB Repository

Once that is all typed out, you can close the file and save the changes by pressing Control + X  then entering Y. This will bring you back to the command line (out of the text editor).

Now you are ready to install MongoDB. We will use the yum  command for this, like so:

sudo yum install mongodb-org -y

Entering the above command will start the installation process, which can take a few minutes. Though once completed, MongoDB will be ready to use. To start the server, you would type:

sudo service mongod start

How To Install MongoDB on Debian

Login to your server via SSH.

After successfully logging in, like the above steps for CentOS, you'll want to add the repository to the package manager. To do this, it'll require an additional step. Start by running this command here:

sudo apt-key adv --keyserver hkp:// --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5

Using the package manager to install MongoDB, apt requires that packages are signed with GPG keys. That command imports the MongoDB public GPG key for us to use. Now you'll want to add the repository for MongoDB to the package manager. This will usually depend on the version of Debian that you use.

Debian 7:

echo "deb wheezy/mongodb-org/3.6 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list

Debian 8:

echo "deb jessie/mongodb-org/3.6 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list

After executing the proper command for the version you have, you'll want to update the local package database. Luckily this command is not as long or complicated. This can be done by typing:

sudo apt-get update

Once that is done and has completed its execution, you'll install MongoDB. Very similar to how it's done in CentOS, you can do this by typing the command:

sudo apt-get install mongodb-org -y

This can take a little bit of time to run and install the required dependencies. But once it has finished, you are now able to start using MongoDB on your server! To start the MongoDB server, you can do so by typing this last command:

sudo service mongod start

By default, some MongoDB installations will not have Authentication enabled. You can do this by modifying the security: authorization: field to be enabled.

If you should have any questions or would like assistance, please contact us through Live Chat or by submitting a ticket with our Technical Support team.

Written by Hostwinds Team  /  April 26, 2018