How To Install MongoDB 4.4 / 4.2 On Debian 9 | Holhol24
MongoDB is an open-source cross-platform, document-oriented database and it was designed with both scalability and developer agility in mind. MongoDB is written in C, C++, and JavaScript, and it uses JSON-like documents with dynamic schemas to store data.
MongoDB is released under the Server Side Public License (SSPL), and the language drivers are available under an Apache License.
MongoDB is available for Linux, Windows, OS X, FreeBSD, and Solaris.
Add MongoDB Repository
MongoDB Inc releases stable packages for Debian 9, and their packages are generally fresher than those in the Debian repositories.
You should always use the official mongodb-org package.
The mongodb-org package might conflict with the mongodb packages in the Debian repository (If you have it already installed).
Install the certificate server for downloading and managing certificates.
sudo apt update sudo apt install -y dirmngr gnupg
Add the MongoDB repository to the system.
MongoDB 4.4
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
MongoDB 4.2
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add - echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.2 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
MongoDB 4.0
wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add - echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/4.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
Install MongoDB
Update the repository index.
sudo apt update
Install the MongoDB packages using the apt command. The name of the MongoDB package is mongodb-org.
sudo apt install -y mongodb-org
Post Installation
File System (Optional)
We recommend you use the XFS filesystem for MongoDB (/var/lib/mongodb).
Access Control
By default, MongoDB doesn’t have authentication mechanisms enabled, which means anyone can read and modify data.
First, create an administrative account to manage databases.
Then, to restrict the access, you would need to enable access control that allows only identified users to perform actions based on their roles.
sudo nano /etc/mongod.conf
Add the below lines.
security: authorization: enabled
Manage MongoDB Service
MongoDB services can be started/stopped by the easy known commands.
To start MongoDB service, run.
sudo systemctl start mongod
To enable MongoDB service to start automatically on system startup, run:
sudo systemctl enable mongod
To check the status of MongoDB service, run.
sudo systemctl status mongod
Output:
● mongod.service - MongoDB Database Server Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2020-08-05 18:28:09 UTC; 8s ago Docs: https://docs.mongodb.org/manual Main PID: 2460 (mongod) CGroup: /system.slice/mongod.service └─2460 /usr/bin/mongod --config /etc/mongod.conf Aug 05 18:28:09 debian9-2g-1 systemd[1]: Started MongoDB Database Server.
Confirm the version of MongoDB.
mongod --version
Output:
db version v4.4.0 Build Info: { "version": "4.4.0", "gitVersion": "563487e100c4215e2dce98d0af2a6a5a2d67c5cf", "openSSLVersion": "OpenSSL 1.1.0l 10 Sep 2019", "modules": [], "allocator": "tcmalloc", "environment": { "distmod": "debian92", "distarch": "x86_64", "target_arch": "x86_64" } }
Access MongoDB
Connect to MongoDB shell by using the mongo command.
mongo
Output:
MongoDB shell version v4.4.0 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("7cf36f27-f692-4f65-b81f-cec8a7dd41ae") } MongoDB server version: 4.4.0 >
Conclusion
That’s All. I hope you have learned how to install MongoDB on Debian 9. Please share your feedback in the comments section.