{"id":14028,"date":"2024-06-17T11:00:13","date_gmt":"2024-06-17T08:00:13","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=14028"},"modified":"2024-06-17T11:00:16","modified_gmt":"2024-06-17T08:00:16","slug":"how-to-install-mongodb-community-edition-on-debian-12","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/how-to-install-mongodb-community-edition-on-debian-12\/","title":{"rendered":"How to Install MongoDB Community Edition on Debian 12 Linux Systems"},"content":{"rendered":"\n
MongoDB is a powerful, open-source NoSQL database that provides high performance, high availability, and easy scalability. This guide will walk you through the steps to install MongoDB Community Edition on a Debian 12 system.<\/p>\n\n\n\n
Before starting, ensure you have:<\/p>\n\n\n\n
First, update your system to ensure all existing packages are up to date.<\/p>\n\n\n\n
$ sudo apt update\n$ sudo apt upgrade -y<\/code><\/pre>\n\n\n\nStep 2: Import the MongoDB Public GPG Key<\/h3>\n\n\n\n
MongoDB provides a GPG key to verify the authenticity of the packages. Import the MongoDB public GPG key using the following command:<\/p>\n\n\n\n
$ wget -qO - https:\/\/www.mongodb.org\/static\/pgp\/server-6.0.asc | sudo apt-key add -<\/code><\/pre>\n\n\n\nStep 3: Create a MongoDB List File<\/h3>\n\n\n\n
Create a list file for MongoDB. This file contains the repository details from which MongoDB packages will be downloaded.<\/p>\n\n\n\n
$ echo "deb [ arch=amd64,arm64 ] https:\/\/repo.mongodb.org\/apt\/debian buster\/mongodb-org\/6.0 main" | sudo tee \/etc\/apt\/sources.list.d\/mongodb-org-6.0.list<\/code><\/pre>\n\n\n\nStep 4: Update Package List<\/h3>\n\n\n\n
After adding the repository, update the package list to include the new MongoDB repository.<\/p>\n\n\n\n
$ sudo apt update<\/code><\/pre>\n\n\n\nStep 5: Install MongoDB Packages<\/h3>\n\n\n\n
Install MongoDB Community Edition packages using the following command:<\/p>\n\n\n\n
$ sudo apt install -y mongodb-org<\/code><\/pre>\n\n\n\nStep 6: Start and Enable MongoDB Service<\/h3>\n\n\n\n
Start the MongoDB service and enable it to start on boot.<\/p>\n\n\n\n
$ sudo systemctl start mongod\n$ sudo systemctl enable mongod<\/code><\/pre>\n\n\n\nStep 7: Verify MongoDB Installation<\/h3>\n\n\n\n
To verify that MongoDB is installed and running correctly, check the status of the MongoDB service.<\/p>\n\n\n\n
$ sudo systemctl status mongod<\/code><\/pre>\n\n\n\nYou should see output indicating that the MongoDB service is active and running.<\/p>\n\n\n\n
Step 8: Configure MongoDB<\/h3>\n\n\n\n
MongoDB configuration files are located in the \/etc\/mongod.conf<\/code> directory. The default configuration is typically sufficient for many users, but you can customize it to suit your specific requirements.<\/p>\n\n\n\nAccess MongoDB Shell<\/h4>\n\n\n\n
To access the MongoDB shell, use the following command:<\/p>\n\n\n\n
$ mongo<\/code><\/pre>\n\n\n\nThis command will connect to the MongoDB instance and drop you into the MongoDB shell.<\/p>\n\n\n\n
Step 9: Secure MongoDB<\/h3>\n\n\n\n
It’s important to secure your MongoDB installation by enabling authentication and setting up a user with the appropriate roles.<\/p>\n\n\n\n
Enable Authentication<\/h4>\n\n\n\n
Edit the MongoDB configuration file to enable authentication.<\/p>\n\n\n\n
$ sudo nano \/etc\/mongod.conf<\/code><\/pre>\n\n\n\nFind the security section and add the following line:<\/p>\n\n\n\n
security:\n authorization: enabled<\/code><\/pre>\n\n\n\nSave the file and exit the text editor. Restart the MongoDB service to apply the changes.<\/p>\n\n\n\n
$ sudo systemctl restart mongod<\/code><\/pre>\n\n\n\nCreate an Administrative User<\/h4>\n\n\n\n
Access the MongoDB shell and create an administrative user.<\/p>\n\n\n\n
$ mongo<\/code><\/pre>\n\n\n\nSwitch to the admin database.<\/p>\n\n\n\n
use admin<\/code><\/pre>\n\n\n\nCreate a new user with the userAdminAnyDatabase<\/code> role.<\/p>\n\n\n\ndb.createUser(\n {\n user: "admin",\n pwd: "your_password",\n roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]\n }\n)<\/code><\/pre>\n\n\n\nExit the MongoDB shell.<\/p>\n\n\n\n
exit<\/code><\/pre>\n\n\n\nAuthenticate with the Administrative User<\/h4>\n\n\n\n
Access the MongoDB shell using the administrative user credentials.<\/p>\n\n\n\n
$ mongo -u admin -p --authenticationDatabase admin<\/code><\/pre>\n\n\n\nConclusion<\/h3>\n\n\n\n
You have successfully installed and configured MongoDB Community Edition on your Debian 12 system. MongoDB is now ready for you to start developing applications with a robust and scalable NoSQL database. For more detailed configurations and advanced usage, refer to the official MongoDB documentation<\/a>.<\/p>\n\n\n\nHappy databasing!<\/p>\n\n\n\n
References<\/h3>\n\n\n\n\n- MongoDB Official Documentation<\/a><\/li>\n\n\n\n
- Debian Official Website<\/a><\/li>\n\n\n\n
- MongoDB Installation Guide<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"
MongoDB is a powerful, open-source NoSQL database that provides high performance, high availability, and easy scalability. This guide will walk you through the steps to install MongoDB Community Edition on…<\/p>\n","protected":false},"author":1,"featured_media":14286,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,9,28,16,18],"tags":[177,180,183,193,354,384,424,433,449,531,573,591],"yoast_head":"\n
How to Install MongoDB Community Edition on Debian 12<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n\n\n\n\n\n\t\n\t\n\t\n