![]() |
MongoDB is a flexible, powerful, and super-fast database management system. Unlike those old-school databases with strict rules, MongoDB lets you store your data in flexible documents, similar to how you organize things in JSON. This means you can easily add new information or change things up without much hassle. In this article, we will install MongoDB on CentOS using two methods. Table of Content How to Install MongoDB on CentOS?To install MongoDB on CentOS, choose between RPM Package or Official Repository methods. Follow step-by-step instructions, including downloading packages, installing dependencies, configuring repositories, and starting services. Let’s see how to do this with proper demonstration.
Method 1: Installing MongoDB Using RPM PackageStep 1: Download RPM package from MongoDB website.We will need to download these 6 mongoDB package from official mongoDB RPM repository to get complete featurs of mongodb. We will use wget command for that. Package 1: mongodb-orgwget https://repo.mongodb.org/yum/redhat/9/mongodb-org/7.0/x86_64/RPMS/mongodb-org-7.0.6-1.el9.x86_64.rpm
![]() downloading mongodb-org.rpm package Package 2: mongodb-mongoshwget https://repo.mongodb.org/yum/redhat/9Server/mongodb-org/7.0/x86_64/RPMS/mongodb-mongosh-2.1.5.x86_64.rpm
![]() downloading mongodb-mongosh.rpm package Package 3: mongodb-org-mongoswget https://repo.mongodb.org/yum/redhat/9Server/mongodb-org/7.0/x86_64/RPMS/mongodb-org-mongos-7.0.6-1.el9.x86_64.rpm
![]() downloading mongodb-org-mongos.rpm package Package 4: mongodb-org-toolswget https://repo.mongodb.org/yum/redhat/9Server/mongodb-org/7.0/x86_64/RPMS/mongodb-org-tools-7.0.6-1.el9.x86_64.rpm
![]() downloading mongodb-org-tools.rpm package Package 5: mongodb-org-databasewget https://repo.mongodb.org/yum/redhat/9Server/mongodb-org/7.0/x86_64/RPMS/mongodb-org-database-7.0.6-1.el9.x86_64.rpm
![]() downloading mongodb-org-database.rpm package Package 6: mongodb-org-serverwget https://repo.mongodb.org/yum/redhat/9Server/mongodb-org/7.0/x86_64/RPMS/mongodb-org-server-7.0.5-1.el9.x86_64.rpm
![]() downloading mongodb-org-server.rpm package Step 2: Install MongoDBInstalling dependencies:cyrus-sasl and openssl are the dependencies that are required by some packages, we will install those dependencies first before installing .rpm packages using yum package manager. sudo yum install cyrus-sasl openssl -y
![]() resolving dependencies We will use rpm -i command to install the downloaded rpm package. Syntax: sudo rpm -i <package-name> sudo rpm -i mongodb-*
![]() completed installation Installation is completed. Now you can move on to starting services section. Method 2: Installing MongoDB Using Official RepositoryStep 1: Configure package management systemCreate a /etc/yum.repos.d/mongodb-org-7.0.repo file so that you can install MongoDB directly using yum. To do that we will use nano editor. sudo nano /etc/yum.repos.d/mongodb-org-7.0.repo
Now paste the following into the terminal (use Ctrl+Shift+V to paste inside of a terminal). [mongodb-org-7.0] Once pasted, press Ctrl + s to save and Ctrl + x to exit the editor. Step 2: Install mongodbNow, we can use yum package manager to install yum directly to our system. sudo yum install -y mongodb-org mongodb-org-database mongodb-org-server mongodb-mongosh-shared-openssl3 mongodb-org-mongos mongodb-org-tools
![]() installing mongodb using yum package manager Starting MongoDB Services After InstallationAfter completing installation, we will start services for the mongodb using systemctl command. sudo systemctl enable mongod ![]() starting mongodb services Running MongoDB with MongoDB ShellYou can run mongoDB using mongodb shell, using following command. ![]() running MongoDB How to Verify MongoDB Installation on CentOS?You can verify the installation using following command sudo systemctl status mongod
It should give output as follows ![]() mongodb status How to Uninstall MongoDB?Step 1: Stop mongodb servicessudo service mongod stop
Step 2: Remove packagessudo yum erase $(rpm -qa | grep mongodb-org)
Step 3: Remove data directoriessudo rm -r /var/log/mongodb ![]() removing mongoDB completely ConclusionIn conclusion, MongoDB on CentOS offers flexibility and speed in data management. The installation, discussed in two methods, ensures compatibility and ease. Utilize MongoDB for efficient, secure, and regularly updated database operations. Also Read
Frequently Asked Questions to Install MongoDB on CentOSHow to resolve wget command not found error?
How can I install MongoDB on CentOS without internet access?
|
Reffered: https://www.geeksforgeeks.org
TechTips |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |