• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Install MongoDB 4.2 on CentOS/RHEL 8/7/6

Written by Rahul, Updated on October 30, 2019

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/

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

13 Comments

  1. Avatar Joshua J Kugler Reply
    October 29, 2019 at 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

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

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

  2. Avatar Jaffer2x Reply
    July 29, 2019 at 4:14 pm

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

  3. Avatar Orest Reply
    June 7, 2019 at 7:07 pm

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

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

      Thanks Orest, Updated tutorial

  4. Avatar dude Reply
    July 20, 2018 at 2:08 pm

    sweeet! love the repo file

  5. Avatar Blah Reply
    March 18, 2018 at 10:42 pm

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

  6. Avatar pp Reply
    June 23, 2016 at 11:43 pm

    thanks a lot for the clear instructions!!

  7. Avatar tamoz Reply
    November 29, 2015 at 8:12 pm

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

  8. Avatar Mark Reply
    June 13, 2015 at 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

  9. Avatar Erin Roberts Reply
    December 10, 2014 at 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.

  10. Avatar Jindra Reply
    July 3, 2014 at 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…

  11. Avatar Simon Reply
    May 21, 2014 at 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

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
  • How To Install NVM on macOS with Homebrew 0
  • (Solved) apt-add-repository command not found – Ubuntu & Debian 0
  • How to Install .NET Core on Debian 10 0
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy