MongoDB is an open-source document database that provides high performance, high availability, and automatic scaling. MongoDB is developed by MongoDB Inc. and is published under a combination of the GNU Affero General Public License and the Apache License.
In this guide, we will explain how to install and configure MongoDB on an Ubuntu 16.04 server.
To install MongoDB on CentOS 7, you can follow the guide here
Deploying your cloud server
If you have not already registered with Cloudwafer, you should begin by getting signed up. Take a moment to create an account after which you can easily deploy your own cloud servers.
Once you have signed up, log into your Cloudwafer Client Area and deploy your
Cloudwafer cloud server.
Updating System Packages
It is always recommended that you update the system to the latest packages before beginning any major installations. This is done with the command below:
sudo apt-get update && sudo apt-get upgrade
Step 1: Import MongoDB Community Edition Public Key:
The Ubuntu package management tools (i.e. dpkg and apt) ensure package consistency and authenticity by requiring that distributors sign packages with GPG keys. Run the following command to import the
MongoDB public GPG Key:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
Step 2: Create a list file for MongoDB
Run the command below to create the list file for MongoDB 4.0:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
You can view the list using the command below:
Step 3: Reload local package database
Run the following command to reload the local package database:
sudo apt-get update
Step 4: Install the MongoDB packages
To install the latest stable version of MongoDB, run the command below:
sudo apt-get install -y mongodb-org
You can install a specific version of MongoDB by specifying each component package individually along with the version number, as in the following example:
sudo apt-get install -y mongodb-org=4.0.3 mongodb-org-server=4.0.3 mongodb-org-shell=4.0.3 mongodb-org-mongos=4.0.3 mongodb-org-tools=4.0.3
Note: The unofficial mongodb package provided by Ubuntu is not maintained by MongoDB and conflict with MongoDB’s officially supported packages. Use the official MongoDB mongodb-org packages, which are kept up-to-date with the most recent major and minor MongoDB releases.
Step 5: Start MongoDB:
Issue the following command to start
sudo service mongod start
Step 6: Check status of MongoDB:
Issue the following command to view the status of
sudo service mongod status
You can also cerify that the
mongod process has started successfully by checking the contents of the log file at
Step 7: Begin using MongoDB
Run the command below to start a mongo shell on the same host machine using the localhost address (in this case 127.0.0.1) and port that the mongod listens on by running the command below
mongo --host 127.0.0.1:27017