Geekflare is supported by our audience. We may earn affiliate commissions from buying links on this site.
In Database Last updated: October 29, 2022
Share on:
Invicti Web Application Security Scanner – the only solution that delivers automatic verification of vulnerabilities with Proof-Based Scanning™.

A step-by-step guide to install the latest version of MongoDB Community Edition on CentOS.

MongoDB, one of the popular NoSQL database, is available for recently released CentOS 8. Let’s check out how to get it installed.

Update – if you are looking for production-ready managed MongoDB then you should check out these hosting platforms.

Installing on CentOS/RHEL 8

Support for CentOS 8 is available from MongoDB 4.2.1. This means you can’t install the previous MongoDB version, like the 3.x series. So, if you are currently running MongoDB (lower than 4.2.1 version) on CentOS 7 and thinking to migrate the server, then you also got to consider upgrading MongoDB.

I assume you have logged in to the server with a root or sudo privilege account.

  • Create a file /etc/yum.repos.d/mongodb-org-4.2.repo with the following content
name=MongoDB Repository

Note: above, I am getting MongoDB 4.2 installed. However, if you need to install different versions, then update the 4.2 info with the desired ones. You can refer to the official MongoDB repo page to find out the available version.

  • and then, install using yum command
yum install -y mongodb-org

It will take a few seconds, and once done, you should see something like below.

[root@lab ~]# yum install -y mongodb-org
CentOS-8 - AppStream                                                                                                                    2.0 kB/s | 4.3 kB     00:02    
CentOS-8 - Base                                                                                                                         1.7 kB/s | 3.9 kB     00:02    
CentOS-8 - Extras                                                                                                                       744  B/s | 1.5 kB     00:02    
CentOS-8 - PowerTools                                                                                                                   1.7 kB/s | 4.3 kB     00:02    
Google Cloud SDK                                                                                                                        205  B/s | 454  B     00:02    
Google Compute Engine                                                                                                                   199  B/s | 454  B     00:02    
MongoDB Repository                                                                                                                      2.0 kB/s | 4.5 kB     00:02    
Dependencies resolved.
 Package                                      Arch                             Version                                  Repository                                 Size
 mongodb-org                                  x86_64                           4.2.2-1.el8                              mongodb-org-4.2                            10 k
Installing dependencies:
 mongodb-org-mongos                           x86_64                           4.2.2-1.el8                              mongodb-org-4.2                            14 M
 mongodb-org-server                           x86_64                           4.2.2-1.el8                              mongodb-org-4.2                            25 M
 mongodb-org-shell                            x86_64                           4.2.2-1.el8                              mongodb-org-4.2                            17 M
 mongodb-org-tools                            x86_64                           4.2.2-1.el8                              mongodb-org-4.2                            47 M

Transaction Summary
Install  5 Packages

Total download size: 103 M
Installed size: 260 M
Downloading Packages:
(1/5): mongodb-org-4.2.2-1.el8.x86_64.rpm                                                                                               9.1 kB/s |  10 kB     00:01    
(2/5): mongodb-org-mongos-4.2.2-1.el8.x86_64.rpm                                                                                        9.1 MB/s |  14 MB     00:01    
(3/5): mongodb-org-shell-4.2.2-1.el8.x86_64.rpm                                                                                          31 MB/s |  17 MB     00:00    
(4/5): mongodb-org-server-4.2.2-1.el8.x86_64.rpm                                                                                         14 MB/s |  25 MB     00:01    
(5/5): mongodb-org-tools-4.2.2-1.el8.x86_64.rpm                                                                                          59 MB/s |  47 MB     00:00    
Total                                                                                                                                    44 MB/s | 103 MB     00:02     
warning: /var/cache/dnf/mongodb-org-4.2-fddc3ec541fac48b/packages/mongodb-org-4.2.2-1.el8.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 058f8b6b: NOKEY
MongoDB Repository                                                                                                                      1.5 kB/s | 1.7 kB     00:01    
Importing GPG key 0x058F8B6B:
 Userid     : "MongoDB 4.2 Release Signing Key <>"
 Fingerprint: E162 F504 A20C DF15 827F 718D 4B7C 549A 058F 8B6B
 From       :
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                1/1 
  Installing       : mongodb-org-tools-4.2.2-1.el8.x86_64                                                                                                           1/5 
  Installing       : mongodb-org-shell-4.2.2-1.el8.x86_64                                                                                                           2/5 
  Running scriptlet: mongodb-org-server-4.2.2-1.el8.x86_64                                                                                                          3/5 
  Installing       : mongodb-org-server-4.2.2-1.el8.x86_64                                                                                                          3/5 
  Running scriptlet: mongodb-org-server-4.2.2-1.el8.x86_64                                                                                                          3/5 
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/mongod.service.

  Installing       : mongodb-org-mongos-4.2.2-1.el8.x86_64                                                                                                          4/5 
  Installing       : mongodb-org-4.2.2-1.el8.x86_64                                                                                                                 5/5 
  Running scriptlet: mongodb-org-4.2.2-1.el8.x86_64                                                                                                                 5/5 
  Verifying        : mongodb-org-4.2.2-1.el8.x86_64                                                                                                                 1/5 
  Verifying        : mongodb-org-mongos-4.2.2-1.el8.x86_64                                                                                                          2/5 
  Verifying        : mongodb-org-server-4.2.2-1.el8.x86_64                                                                                                          3/5 
  Verifying        : mongodb-org-shell-4.2.2-1.el8.x86_64                                                                                                           4/5 
  Verifying        : mongodb-org-tools-4.2.2-1.el8.x86_64                                                                                                           5/5 

  mongodb-org-4.2.2-1.el8.x86_64           mongodb-org-mongos-4.2.2-1.el8.x86_64     mongodb-org-server-4.2.2-1.el8.x86_64     mongodb-org-shell-4.2.2-1.el8.x86_64    

[root@lab ~]#

Let’s verify the version to ensure it has installed.

[root@lab ~]# mongo --version
MongoDB shell version v4.2.2
git version: a0bbbff6ada159e19298d37946ac8dc4b497eadf
OpenSSL version: OpenSSL 1.1.1 FIPS  11 Sep 2018
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel80
    distarch: x86_64
    target_arch: x86_64
[root@lab ~]#

There you go!

MongoDB is successfully installed.

Next, explore MongoDB commands to learn more.

  • Chandan Kumar
    As the founder of Geekflare, I’ve helped millions to excel in the digital realm. Passionate about technology, I’m on a mission to explore the world and amplify growth for professionals and businesses alike.
Thanks to our Sponsors
More great readings on Database
Power Your Business
Some of the tools and services to help your business grow.
  • Invicti uses the Proof-Based Scanning™ to automatically verify the identified vulnerabilities and generate actionable results within just hours.
    Try Invicti
  • Web scraping, residential proxy, proxy manager, web unlocker, search engine crawler, and all you need to collect web data.
    Try Brightdata
  • is an all-in-one work OS to help you manage projects, tasks, work, sales, CRM, operations, workflows, and more.
    Try Monday
  • Intruder is an online vulnerability scanner that finds cyber security weaknesses in your infrastructure, to avoid costly data breaches.
    Try Intruder