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.
- 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,
- 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.
- After you have brought the new file open for editing, you’ll want to type in the following:
- 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:
1sudo 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 just type:
1sudo service mongod start
How To Install MongoDB on Debian
- Login to your server via SSH.
- 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:
1sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
- 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:
1echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.6 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
- Debian 8:
1echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.6 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
- Debian 7:
- 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:
1sudo apt-get update
- 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:
1sudo 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:
1sudo 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.
- How To Install MongoDB Community Edition – Useful resource on MongoDB’s site on how to install with various versions of Linux.
- How To Install Node.js On Linux – Another useful article if you are looking to get the MEAN stack setup, or use Node.js with MongoDB.
If you should have any questions or would like assistance, do feel free to contact us through Live Chat, on our Phones, or by submitting a ticket with our Technical Support team.