• Get application security done the right way! Detect, Protect, Monitor, Accelerate, and more…
  • 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
    [mongodb-org-4.2]
    name=MongoDB Repository
    baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
    gpgcheck=1
    enabled=1
    gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

    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.

    [[email protected] ~]# 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
    ========================================================================================================================================================================
    Installing:
     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 <[email protected]>"
     Fingerprint: E162 F504 A20C DF15 827F 718D 4B7C 549A 058F 8B6B
     From       : https://www.mongodb.org/static/pgp/server-4.2.asc
    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/multi-user.target.wants/mongod.service → /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 
    
    Installed:
      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    
      mongodb-org-tools-4.2.2-1.el8.x86_64    
    
    Complete!
    [[email protected] ~]#

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

    [[email protected] ~]# 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
    [[email protected] ~]#

    There you go!

    MongoDB is successfully installed.

    Next, explore MongoDB commands to learn more.