Search The Hostwinds Guides Knowledge Base

How To Install MongoDB on Linux

Share This Article [TheChamp-Sharing]

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, not only is the data stored differently, that data is also accessed in a different way. MongoDB mostly works through API calls. This allows MongoDB to easily be used with various programming languages for the database.

Here we’ll show you how to get MongoDB installed and setup 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 quite similar to those of Fedora and other RHELinux operating systems. For that, you’ll want to follow these steps.

  1. Login to your server using SSH.
  2. 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
  3. This will bring you to the repositories directory. In here you’ll want to create a file called mongodb-org-3.6.repo and input some specific contents. To edit the file, you can do this with the nano  command or by using your favorite text editor.
    nano mongodb-org-3.6.repo
  4. After you have brought the new file open for editing, you’ll want to type in the following:
    name=MongoDB Repository
  5. 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).
  6. Now you are ready to install MongoDB. We will use the yum  command for this, like so:
    sudo yum install mongodb-org -y
  7. 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 just type:


    sudo service mongod start

How To Install MongoDB on Debian

  1. Login to your server via SSH.
  2. After you have successfully logged 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
  3. The package manager that we will be using 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
  4. After executing the proper command for the version that 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
  5. Once that is done and has completed it’s 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
  6. 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.

Related Links

Related Articles

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