Install MongoDB on Ubuntu
MongoDB – a NO-SQL database
Like Redis and RethinkDB, MongoDB is a no-SQL DB, a database which does not correspond to the classic SQL system, but stores complete objects in strings and then provides them for querying or filtering. This new technology is not only faster and more effective than the classic SQL databases, it also offers completely new methods of data storage.
This tutorial shows how MongoDB can be installed on an Ubuntu 16.04 LTS server.
For the tutorial an average of about 4 minutes is required. Should it be tried out, but not installed on your productive system? Then it is recommended to create a new server at gridscale, which takes only a few seconds. How this works, is shown in this article (German only).
Preparing the server
As before every installation, the server should be updated. All updates and upgrades must be downloaded and installed. On Ubuntu, the package manager APT takes most of the work as soon as the process is started with the following command:
apt -y update && apt -y upgrade && apt -y dist-upgrade
As with RethinkDB (German only), MongoDB is not yet in the official Ubuntu repository. Therefore, the Developer Repository must be manually added and then loaded:
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list apt -y update
After the server is up to date, it is possible to install all necessary tools.
APT is also doing work here. Just execute the following command and APT will take care of the rest:
apt -y install mongodb-org
Afterwards the service for SystemD has to be defined. To do this, the /etc/systemd/system/mongodb.service file must be created and edited with an editor. In this example, nano is used:
The following content must be inserted into the file:
[Unit] Description=High-performance, schema-free document-oriented database After=network.target [Service] User=mongodb ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf [Install] WantedBy=multi-user.target
After this, Nano can be terminated with the key combination Ctrl + X and the changes can be saved by answering the question with Y.
You can then use the following command to enable MongoDB to boot automatically:
sudo systemctl enable mongodb
Set up MongoDB
After MongoDB is now set up successfully, the service can be started with the following command:
service mongodb start
To display the current status, the following command can be used:
service mongodb status
Other parameters are stop to terminate the server and restart to restart the server.
With these few steps, MongoDB can be installed on a server and ready for the new generation of databases. In the long run, no-SQL DBs will certainly replace the classic SQL DBs. Therefore, it is worth looking at applications like RethinkDB, MongoDB or Redis. More information about installing RethinkDB and Redis can be found in the articles “Installing Redis on Ubuntu 16.04 LTS” and “Installing RethinkDB on Ubuntu” (both German only)Zurück zur Tutorial Übersicht Back to Tutorial Overview
MongoDB – a NO-SQL database Like Redis and RethinkDB, MongoDB is a no-SQL DB, a database which does not correspond to the classic SQL system, but stores complete objects in strings and then provides them for querying or filtering. This new technology is not only faster and more effective than the classic SQL databases, it also […]
Thank you for your feedback!
We will get back to you as soon as the article is finished.