How to Install MongoDB 4.2 on Debian 9
Install MongoDB 4.2 on Debian 9
MongoDB is a cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas.
It is an open-source database management system that is known as a high-performance NoSQL database program.
MongoDB uses two formats to stores the information i.e. “.json” and “.bson [binary json]”.
Main Features of MongoDB
- Ad-hoc Queries
- Load Balancing
- File Storage
- Capped collections
In this article, We are going to install the latest version of MongoDB 4.2.
The upcoming version is MongoDB 4.4 and we will share the information soon once the MongoDB 4.4 version is officially released.
MongoDB 4.2 Edition supports the following 64-bit Ubuntu releases on x86_64 architecture:
- Debian 10 “Buster” (Starting in MongoDB Community 4.2.1)
- Debian 9 “Stretch”
Note: MongoDB only supports 64-bit server architectures of these platforms.
Install MongoDB 4.2 On Debian 9
1. Import MongoDB public GPG Key
Download the GPG Key with “wget command” and It will respond with output OK,
$ wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
2. Create APT List file for MongoDB
Run the below command which will add repository url directly to the APT list file,
$ echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
Check the APT list file,
$ cat /etc/apt/sources.list.d/mongodb-org-4.2.list
3. Update the APT repository
To reflect the apt list repository, we need to run the below command,
$ apt-get update
4. Install MongoDB 4.2
Install mongodb package that install multiple other packages along with the mongodb. To install mongodb run below command,
$ apt-get install -y mongodb-org
MongoDB Data files stored in “/var/lib/mongodb” & log files stored in “/var/log/mongodb”.
If you faced libcurl3 dependency package error while installing the mongodb-org then install the libcurl3 package.
libcurl3 package is required for MongoDB server.
$ apt-get install libcurl3
5. Check MongoDB Version
$ mongod --version
6. Manage MongoDB Service
MongoDB service starts/stops with the systemctl command and its easily manageable with the standard systemd commands.
To Check Status of MongoDB Service, run the following command.
$ systemctl status mongod.service
To Stop the MongoDB Service, run the following command.
$ systemctl stop mongod.service
To Start the MongoDB Service, run the following command.
$ systemctl start mongod.service
To restart the MongoDB Service, run the following command.
$ systemctl restart mongod.service
To Enable/Disable MongoDB Service at boot time, run the following command.
$ systemctl enable mongodb.service
$ systemctl disable mongodb.service
That’s it. You have now installed MongoDB 4.2 successfully on Debian 9 Stretch server.
If you are new to MongoDB and want to learn further on MongoDB like to create a new database, create a user with privileges, backup, restore MongoDB.