How to Install MongoDB on CentOS?
Last Updated :
21 Mar, 2024
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.
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.
Also Learn MongoDB with this Tutorial
Method 1: Installing MongoDB Using RPM Package
Step 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-org
wget 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 packagePackage 2: mongodb-mongosh
wget 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-mongos
wget 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 packagePackage 4: mongodb-org-tools
wget 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 packagePackage 5: mongodb-org-database
wget 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 packagePackage 6: mongodb-org-server
wget 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 packageStep 2: Install MongoDB
Installing 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 dependenciesWe will use rpm -i command to install the downloaded rpm package.
Syntax: sudo rpm -i <package-name>
sudo rpm -i mongodb-*
completed installationInstallation is completed. Now you can move on to starting services section.
Method 2: Installing MongoDB Using Official Repository
Step 1: Configure package management system
Create 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]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/9/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://pgp.mongodb.com/server-7.0.asc

Once pasted, press Ctrl + s to save and Ctrl + x to exit the editor.
Step 2: Install mongodb
Now, 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 managerStarting MongoDB Services After Installation
After completing installation, we will start services for the mongodb using systemctl command.
sudo systemctl enable mongod
sudo systemctl start mongod
starting mongodb services Running MongoDB with MongoDB Shell
You can run mongoDB using mongodb shell, using following command.
running MongoDBHow 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 statusHow to Uninstall MongoDB?
Step 1: Stop mongodb services
sudo service mongod stop
Step 2: Remove packages
sudo yum erase $(rpm -qa | grep mongodb-org)
Step 3: Remove data directories
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongo
removing mongoDB completelyConclusion
In 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
Similar Reads
How to Install MongoDB on cPanel?
cPanel is a web hosting management system. cPanel provides a control panel that provides a nice user interface. It is the most reliable site management system. Moreover, cPanel provides a dashboard where some web date files and MySQL files are present to help others out. MongoDB is a database and it
2 min read
How to Install MongoDB on Android?
MongoDB is a NoSQL document-oriented database used to store data in high volume. Instead of using columns and rows or tables that were used in traditional relational databases like SQL, MongoDB makes use of collections and documents. MongoDB is written in C++ language. MongoDB is developed and manag
9 min read
How to Install MongoDB on Alpine?
MongoDB is an open-source NoSQL database. NoSQL databases are quite useful for working with large sets of distributed data. It is a good choice when your data is document-centric and doesn't fit well into the schema of a relational database. It provides full indexing support and replication with ric
2 min read
How to Install MongoDB Atlas
MongoDB Atlas is a fully-managed cloud database service provided by MongoDB. It simplifies database management by hosting your MongoDB database on the cloud, eliminating the need for local hosting. MongoDB Atlas ensures our database is accessible anytime, with robust security, powerful analytics, sc
4 min read
How to Install MongoDB Compass on Linux?
MongoDB is a free, open-source, cross-platform, document-oriented database. It is also classified as a non-SQL database program. Compass is an interactive tool for querying, optimizing & analyzing MongoDB data. It works in a visual environment. It can be installed in any operating system like Wi
1 min read
How to Install MongoDB Compass on MacOS?
MongoDB Compass is basically a tool to quickly explore your MongoDB data, run queries or even interact with data with full functionalities. It can be referred to as a GUI for MongoDB. It is free to use and can be run on different operating systems such as macOS, Windows, and Linux. The following met
2 min read
How to Install MongoDB on GoormIDE?
GoormIDE is a simple web-based cloud programming tool and MongoDB is a document-oriented NoSQL database, they are used to make efficient software anytime and anywhere. as here during the development of any website or software one required a need of database i.e. MongoDB. so below we discussed two me
3 min read
How to Install MongoDB Enterprise on MacOS?
In complement to SQL, MongoDB is a document database that is part of the NoSQL family of databases. Records in MongoDB are documents, which in JavaScript behave quite similarly to JSON objects. By using the field's key, values in documents can be sought. Because some fields/keys might be present in
2 min read
How to Install MongoDB Enterprise on Windows
MongoDB is a free, open-source, cross-platform, document-oriented database. The MongoDB Enterprise Edition is a commercial version of MongoDB used for enterprise-scale operations. In this guide, we will learn how to install MongoDB Enterprise edition on a Windows System. We have provided a detailed
2 min read
How to Install MongoDB Bi Connector on MacOS?
MongoDB BI connector is a connector for business intelligence that allows you to fabricate different queries using SQL which can be used to envision your data in a more sophisticated way. MongoDB Bi is more advanced than traditional business tools which work only with tabular or flat data. The Mongo
2 min read