{"id":27545,"date":"2018-07-20T02:16:33","date_gmt":"2018-07-20T07:16:33","guid":{"rendered":"https:\/\/www.rosehosting.com\/blog\/?p=27545"},"modified":"2022-06-03T03:34:47","modified_gmt":"2022-06-03T08:34:47","slug":"how-to-install-mongodb-on-debian-9","status":"publish","type":"post","link":"https:\/\/www.rosehosting.com\/blog\/how-to-install-mongodb-on-debian-9\/","title":{"rendered":"How to Install MongoDB on Debian 9"},"content":{"rendered":"
<\/p>\n
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<\/a>.<\/p>\n Some of the key features of MongoDB are listed below: – Debian 9 VPS – 64bit – MongoDB only provides packages for 64-bit builds of Debian 9. <\/p>\n Login to your Debian 9 VPS via SSH<\/a> as user root<\/p>\n and before we start installing MongoDB, make sure that all installed packages are updated to the latest available version<\/p>\n 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<\/p>\n Output:<\/p>\n 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:<\/p>\n Once the repository is added, update the local package database<\/p>\n 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<\/p>\n Check the version of MongoDB installed on the server<\/p>\n Output:<\/p>\n So, we successfully installed MongoDB version 4.0.0 which at the moment of writing this article is the latest stable release.<\/p>\n 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. 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<\/p>\n Once MongoDB is installed, start the service<\/p>\n and verify that the mongod process is running<\/p>\n Output:<\/p>\n 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.<\/a><\/p>\n You can also check our tutorials on how to install MongoDB on Ubuntu 16.04\u00a0VPS<\/a>\u00a0or CentOS VPS<\/a>.<\/p>\n
\n– High Performance Data persistence
\n– Can be used as a file storage
\n– Supports Rich Query Language
\n– High Availability
\n– Deep Query-Ability.
\n– Horizontal Scalability
\n– Support for Multiple Storage You can Engines such as WiredTiger Storage Engine and MMAPv1<\/p>\nPrerequisites<\/strong><\/h3>\n
\n– SSH access with root privileges (All our VPS hosting plans come with full root access).<\/p>\nLogin to the server and update the system<\/strong><\/h3>\n
ssh root@IP_Address -p Port_number<\/pre>\n
apt update && apt update<\/pre>\n
Add MongoDB’s official repository<\/strong><\/h3>\n
apt-key adv --keyserver hkp:\/\/keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4<\/pre>\n
Executing: \/tmp\/apt-key-gpghome.BvSKWq7GUg\/gpg.1.sh --keyserver hkp:\/\/keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4\r\ngpg: key 68818C72E52529D4: public key \"MongoDB 4.0 Release Signing Key <packaging@mongodb.com>\" imported\r\ngpg: Total number processed: 1\r\ngpg: imported: 1<\/pre>\n
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<\/pre>\n
apt update<\/pre>\n
Install MongoDB on Debian 9<\/strong><\/h3>\n
apt -y install mongodb-org<\/pre>\n
mongo -version<\/pre>\n
MongoDB shell version v4.0.0\r\ngit version: 3b07af3d4f471ae89e8186d33bbb1d5259597d51\r\nOpenSSL version: OpenSSL 1.1.0f 25 May 2017\r\nallocator: tcmalloc\r\nmodules: none\r\nbuild environment:\r\n distmod: debian92\r\n distarch: x86_64\r\n target_arch: x86_64<\/pre>\n
\nsudo 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<\/p>\necho \"mongodb-org hold\" | sudo dpkg --set-selections\r\necho \"mongodb-org-server hold\" | sudo dpkg --set-selections\r\necho \"mongodb-org-shell hold\" | sudo dpkg --set-selections\r\necho \"mongodb-org-mongos hold\" | sudo dpkg --set-selections\r\necho \"mongodb-org-tools hold\" | sudo dpkg --set-selections<\/pre>\n
service mongod start<\/pre>\n
serive mongod status<\/pre>\n
\u25cf mongod.service - MongoDB Database Server\r\n Loaded: loaded (\/lib\/systemd\/system\/mongod.service; disabled; vendor preset: enabled)\r\n Active: active (running) since Tue 2018-07-17 11:51:26 CDT; 21s ago\r\n Docs: https:\/\/docs.mongodb.org\/manual\r\n Main PID: 21205 (mongod)\r\n CGroup: \/system.slice\/mongod.service\r\n \u2514\u250021205 \/usr\/bin\/mongod --config \/etc\/mongod.conf<\/pre>\n
\n
\n