In today’s article we are going to show you how to install MongoDB on Debian 9. MongoDB is a free and open-source NoSQL document-oriented database which is platform oriented. It stores all data in documents using JSON format (BSON) which makes the data to be highly flexible. MongoDB comes in Community and Enterprise editions. The Enterprise edition provides additional administration, authentication, and monitoring features. Community edition is the free and open source release of MongoDB and we will install it in this tutorial on a Debiab 9 VPS.
Some of the key features of MongoDB are listed below:
– High Performance Data persistence
– Can be used as a file storage
– Supports Rich Query Language
– High Availability
– Deep Query-Ability.
– Horizontal Scalability
– Support for Multiple Storage You can Engines such as WiredTiger Storage Engine and MMAPv1
– Debian 9 VPS – 64bit – MongoDB only provides packages for 64-bit builds of Debian 9.
– SSH access with root privileges (All our VPS hosting plans come with full root access).
Login to the server and update the system
Login to your Debian 9 VPS via SSH as user root
ssh root@IP_Address -p Port_number
and before we start installing MongoDB, make sure that all installed packages are updated to the latest available version
apt update && apt update
Add MongoDB’s official repository
MongoDB can be installed from the official Debian 9 repository, but this package is not maintained by the MongoDB team and it is not an official release by MongoDB. So, in order to install the official MongoDB package which is always kept updated, we need to add the MongoDB repository to the server. First of all we will import the MongoDB public key, to ensure package consistency and authenticity. Run the following command
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
Executing: /tmp/apt-key-gpghome.BvSKWq7GUg/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 gpg: key 68818C72E52529D4: public key "MongoDB 4.0 Release Signing Key <firstname.lastname@example.org>" imported gpg: Total number processed: 1 gpg: imported: 1
The next step is to add the repository by creating a ‘/etc/apt/sources.list.d/mongodb-org-4.0.list’ file using the following command:
echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
Once the repository is added, update the local package database
Install MongoDB on Debian 9
We’ve added the official MongoDB repository to our Debian 9 VPS, so we are ready to start installing the latest version of MongoDB simply by executing the following command on the server
apt -y install mongodb-org
Check the version of MongoDB installed on the server
MongoDB shell version v4.0.0 git version: 3b07af3d4f471ae89e8186d33bbb1d5259597d51 OpenSSL version: OpenSSL 1.1.0f 25 May 2017 allocator: tcmalloc modules: none build environment: distmod: debian92 distarch: x86_64 target_arch: x86_64
So, we successfully installed MongoDB version 4.0.0 which at the moment of writing this article is the latest stable release.
You can also install any specific version of MongoDB you need. If you need an older version of MongoDB, for example 3.0.12 you can install it by executing the following command.
sudo apt-get install -y mongodb-org=3.0.12 mongodb-org-server=3.0.12 mongodb-org-shell=3.0.12 mongodb-org-mongos=3.0.12 mongodb-org-tools=3.0.12
Please note that the version of MongoDB you specified and installed on the server will be automatically upgraded when a new version is released. In order to prevent this, we will put the package on “hold”. This way the MongoDB package cannot be installed, upgraded, or removed until the hold mark is removed. You can achieve this issuing the following commands
echo "mongodb-org hold" | sudo dpkg --set-selections echo "mongodb-org-server hold" | sudo dpkg --set-selections echo "mongodb-org-shell hold" | sudo dpkg --set-selections echo "mongodb-org-mongos hold" | sudo dpkg --set-selections echo "mongodb-org-tools hold" | sudo dpkg --set-selections
Once MongoDB is installed, start the service
service mongod start
and verify that the mongod process is running
serive mongod status
● mongod.service - MongoDB Database Server Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled) Active: active (running) since Tue 2018-07-17 11:51:26 CDT; 21s ago Docs: https://docs.mongodb.org/manual Main PID: 21205 (mongod) CGroup: /system.slice/mongod.service └─21205 /usr/bin/mongod --config /etc/mongod.conf
That’s all, MongoDB is successfully installed and running on your Debian 9 VPS. For more information and instructions on how to use MongoDB, please check their official documentation.
Of course, if you are one of our MongoDB Hosting customers, you don’t have to Install MongoDB on your Debian 9 VPS, simply ask our admins, sit back and relax. Our admins will Install MongoDB on Debian 9 for you immediately.
PS. If you liked this post about How to Install MongoDB on Debian 9 VPS, please share it with your friends on the social networks using the buttons below or simply leave a comment in the comments section. Thanks.