Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Databases»How to Install MongoDB on CentOS/RHEL 7

    How to Install MongoDB on CentOS/RHEL 7

    RahulBy RahulJanuary 1, 20162 Mins ReadUpdated:August 18, 2021

    MongoDB (named from “huMONGOus“) is a full flexible index support and rich queries database. Its is a NoSQL database. MongoDB provides large media storage with GridFS. Click here for more details about mongoDB.

    install mongodb

    MongoDB has released a new stable version 4.2 with lots of major enhancements. This tutorial latest tested on CentOS 7 and help you to install MongoDB 4.2 on CentOS 8/7/6 and RHEL 8/7/6 systems.

    Step 1 – Add MongoDB Yum Repository

    Add the following content in yum repository configuration file mongodb.repo as per your required MongoDB version and system architecture. For this article, we are using MongoDB 4.0 repository.

    CentOS and RedHat systems Only

    vi /etc/yum.repos.d/mongodb.repo
    
    [MongoDB]
    name=MongoDB Repository
    baseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/$basearch/
    gpgcheck=1
    enabled=1
    gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
    

    Step 2 – Install MongoDB Server

    Let’s use the yum package manager to install mongodb-org package, it will automatically install all its dependencies. To install any specific revision of MongoDB specify package name with version like mongodb-org-4.0.0. The following command will install the latest stable version available.

    sudo yum install mongodb-org
    

    Step 3 – Start MongoDB Service

    Package mongodb-org-server provided MongoDB init script, Use that script to start service.

    systemctl start mongod.service    # For CentOS 8/7 
    service mongod restart            # For CentOS 6 
    

    Configure MongoDB to autostart on system boot.

    systemctl enable mongod.service    # For CentOS 8/7 
    chkconfig mongod on                # For CentOS 6 
    

    Step 4 – Check MongoDB Version

    Use the following command to check installed MongoDB version

    [[email protected] ~]# mongod --version
    
    db version v4.2.1
    git version: edf6d45851c0b9ee15548f0f847df141764a317e
    OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
    allocator: tcmalloc
    modules: none
    build environment:
        distmod: rhel70
        distarch: x86_64
        target_arch: x86_64
    

    Connect MongoDB using the command line and execute some test commands for checking proper working.

    [[email protected] ~]#  mongo
    
    > use mydb;
    
    > db.test.save( { a: 1 } )
    
    > db.test.find()
    
      { "_id" : ObjectId("54fc2a4c71b56443ced99ba2"), "a" : 1 }
    
    

    Congratulation’s You have successfully installed mongodb server on your system. For practice only you may use MongoDB browser shell.

    References:
    http://docs.mongodb.org/manual/installation/

    install mongodb mongodb mongodb on linux setup mongodb
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Install Atom Text Editor on Ubuntu, Debian and LinuxMint
    Next Article How to Install MongoDB 4.4 on Ubuntu 18.04 & 16.04 via PPA

    Related Posts

    How to Install MariaDB on Ubuntu 22.04

    Updated:May 28, 20222 Mins Read

    How To Install Linux, Nginx, MySQL, & PHP (LEMP Stack) on Ubuntu 22.04

    Updated:April 7, 20227 Mins Read

    How To Install MySQL Server on Ubuntu 22.04

    Updated:April 6, 20224 Mins Read

    How To Setup Apache, PHP & MongoDB in Ubuntu & Debian

    Updated:October 8, 20213 Mins Read

    How To Install MariaDB on Debian 11

    4 Mins Read

    How to Install Redis on Debian 11 Linux

    Updated:September 16, 20213 Mins Read

    16 Comments

    1. Janardhana on March 7, 2022 3:45 pm

      Thanks for the steps, is it possible to provide steps for how to install MongoDB 2 versions on the same server centos 7.

      Thanks in advance.

      Reply
    2. Rio Regala on December 3, 2021 4:37 am

      stating mongod: FAILED. please help me . Thanks!

      Reply
    3. Aditya on October 14, 2021 12:03 pm

      Great work it gets installed thank you

      Reply
    4. Joshua J Kugler on October 29, 2019 8:04 pm

      Mongo *does* publish their signing keys. There is no reason t disable GPG check, and that could allow malicious packages to be installed via a man-in-the-middle attack. The keys are available here: https://www.mongodb.org/static/pgp/ and the .repo file would then look like this (I did 4.2, so pay attention to versions). 🙂

      [MongoDB]
      name=MongoDB Repository
      baseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/$basearch/
      gpgcheck=1
      enabled=1
      gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

      Reply
      • Rahul on October 30, 2019 7:51 am

        Thanks Joshua, We have updated our tutorials as per your recommendation’s

        Reply
    5. Jaffer2x on July 29, 2019 4:14 pm

      Easiest installation ever, thank you, a nice extra would be the first admin user setup in database. greetings

      Reply
    6. Orest on June 7, 2019 7:07 pm

      /etc/init.d/mongod restart – doesn’t work for me
      systemctl start mongod – solved the problem

      Reply
      • Rahul on June 10, 2019 6:03 am

        Thanks Orest, Updated tutorial

        Reply
    7. dude on July 20, 2018 2:08 pm

      sweeet! love the repo file

      Reply
    8. Blah on March 18, 2018 10:42 pm

      Doesn’t work on Fedora 27. No init/startup scripts.

      Reply
    9. pp on June 23, 2016 11:43 pm

      thanks a lot for the clear instructions!!

      Reply
    10. tamoz on November 29, 2015 8:12 pm

      On Fedora 23 x64 no need to add entry for mongodb in yum.repos.d . Installation works fine without it.

      Reply
    11. Mark on June 13, 2015 7:19 pm

      These instructions are misleading, the title suggests the shown repo files will work on Fedora. Fedora fails because “$releasever” will translate to a Fedora version like “22” but the remote repo only has
      5, 5Server, 6, 6Server, 7, 7Server as available. So when dnf/yum tries to look in the repo there is no repodata available. This seems to work however for the baseurl for Fedora 22:

      baseurl=http://repo.mongodb.org/yum/redhat/7/mongodb-org/3.0/x86_64/

      because RHEL7 is similar enough to Fedora 22

      Reply
    12. Erin Roberts on December 10, 2014 7:30 pm

      Im getting this error

      http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/repodata/primary.xml.gz: [Errno -1] Metadata file does not match checksum

      Something changed on 12/9/14. Can you verify the checksum? Or any other assistance would be great.

      Reply
    13. Jindra on July 3, 2014 2:24 pm

      Thanks for this guide. Pls note that there are some bugs in the latest (2.6.3) of the RPM.
      – it uses the old, deprecated config file format
      – the script /etc/init.d/mongod tries to read pidfile location, but this will not work if you have the new YAML config file
      – on top of that, it calls killproc $PIDFILE (will not work with the new format of config file) instead of calling correctly mongod –shutdown
      – in start() function it calls mongod path stored in $mongod, but in stop() it calls /usr/bin/mongod hardcoded

      Preparation of the RPM package was not done very carefully. There might be other bugs, take care…

      Reply
    14. Simon on May 21, 2014 12:26 pm

      Hi

      Thanks for the step by step guide however when installed it creates a init.d script (bash) and not an init script (upstart) one.

      Simon

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install Ionic Framework on Ubuntu 22.04
    • What is the /etc/hosts file in Linux
    • How to Install Angular CLI on Ubuntu 22.04
    • How to Install Composer on Ubuntu 22.04
    • How to Create DMARC Record For Your Domain
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.