How to Install MongoDB on Ubuntu
Step by Step Guideline on Installing MongoDB on Ubuntu
MongoDB is an ultimate free, open-source, distributed, NoSQL, document database, which serves as the common purpose in modern web applications. It features horizontal scaling, high availability & geographical distribution. There are many things that it supports like Ad hoc queries, indexing, and even real-time aggregation. If you wish to use MongoDB on Ubuntu, it is needful for you to Install MongoDB it first in your system.
In this MongoDB tutorial, you will be understanding installing more simply. So, let’s begin the process, as we have presented a step by step guide, which you can follow for the installation. You will realize a smooth installation in no time if you follow as instructed in this guide.
Step 1: Install MongoDB Package
One gets MongoDB inclusive in the package of Ubuntu Repositories, but considering the official MongoDB repositories, you are provided with a more advanced, up to date version. And it is the ideal way recommended by us to install the software. In this step, one needs to add official repositories into your server. Ubuntu verifies the authenticity of the to-be-installed software by checking that it’s signed with GPS keys.
Importing the key store for official repository
1 |
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 |
After successful importing, add MongoDB details, to let apt know where the package needs to be downloaded from. By following the below command:
1 |
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/MongoDB-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list |
Once it is done, updating the package list is the next command to be followed:
1 |
sudo apt-get update |
Step 2: Verifying MongoDB
After accomplishing the first step, you can move further with the installation of the package itself. Below command will help you install multiple packages that hold the latest version including management tools to help you for the MongoDB server.
1 |
sudo apt-get install -y MongoDB-org |
Once done, start your MongoDB with, systemct1, and you can also check through it if the system service has started properly:
1 2 3 4 |
sudo systemctl start mongod (for starting the system) sudo systemctl stop mongodb (for stopping the system) sudo systemctl restart mongodb (for restarting the system) sudo systemctl status mongod (for checking the service) |
After this, you will see the output results like this:
Output:
1 2 3 4 5 6 7 8 9 |
mongodb.service - High-performance, schema-free document-oriented database Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2016-04-25 14:57:20 EDT; 1min 30s ago Main PID: 4093 (mongod) Tasks: 16 (limit: 512) Memory: 47.1M CPU: 1.224s CGroup: /system.slice/mongodb.service └─4093 /usr/bin/mongod --quiet --config /etc/mongod.conf |
Now, the last step in the verification process is to enable automatically starting of MongoDB as soon as the system starts. This can be performed with the help of the command given below:
1 |
sudo systemctl enable mongod |
Step 3: Adjusting Firewall (Optional)
Assuming that you have understood and gone through all the necessary steps needed, next is to enable the firewall on your server. If you wish to use the MongoDB server for local needs with applications that would be running on the same server. Then, it is highly recommended for you to make a secure setting. You need to allow the incoming connections to ufw
If you wish to allow access from everywhere on the default port of 27017, one can use the following command properly:
1 |
sudo ufw allow 27017 |
Remember, MongoDB should be accessed only through trusted locations. To make it accomplish, allow access on MongoDB’s default port when you are specifying the IP address of other servers, that would be allowed to connect: Following is the command you can need to address, to accomplish the task:
1 |
sudo ufw allow from your_other_server_ip/32 to any port 27017 |
Now that you have understood how to go about it, make sure you follow the steps properly. Your query about How to Install MongoDB on Ubuntu will be solved easily if you make every introduced here, properly.
thanks for the info