Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Installing MongoDB on Red Hat Enterprise Linux

June 2, 2016
Hemant Jain
Related topics:
DatabasesLinux
Related products:
Red Hat Enterprise Linux

Share:

    MongoDB has evolved into one of the most popular open source "NoSQL" databases—so-called because they dispense with the tabular storage schema of relational databases like MySQL and Postgres. NoSQL databases offer a variety of advantages in many cases

    The biggest advantage is that MongoDB databases don't require developers to define schemas before adding data to a database. Instead, they use a flexible document-based model, similar to Python dictionaries or Ruby hashes. With MongoDB, you don't need to spend time creating tables before you can process your data. That makes the NoSQL approach ideal for situations where you don't know how much data you have to handle, what form it is in, or how quickly it is going to move around.

    There's a lot more to say about what makes MongoDB, and NoSQL in general, a better fit for some situations. (I could also write a great deal about when not to use NoSQL—and that’s  important, because despite NoSQL's current trendiness, it's not better in all contexts.)

    But that's all fodder for a separate blog post. For now, let's move onto the meat of this post, which is how to install MongoDB on Red Hat Enterprise Linux (RHEL) in order to take advantage of NoSQL databases.

    Preliminary Notes on MongoDB Installation

    Before delving into the installation steps, we should go over some prerequisites. First, know that this guide applies to systems running RHEL 6 or later. (MongoDB does not support RHEL 5 or earlier.) It probably works pretty well for CentOS and other RHEL derivatives, but I haven’t tested those.

    I also assume you want to install MongoDB using RPM packages and the yum package manager, which ships with RHEL. You could also compile MongoDB from source, but that is a lot more complicated and, for my money, not worth the trouble (pace, Gentoo fans).

    You should also know that MongoDB no longer supports 32-bit systems. While it's technically possible to install MongoDB on a 32-bit RHEL system using outdated, archived versions of MongoDB packages, you probably don't want to do that—certainly not if you have any intention of using MongoDB in a production environment. So your RHEL server needs to be running a 64-bit kernel to follow this guide.

    Note also that this guide is designed to allow you to install the latest stable version of MongoDB on RHEL. At the time of this writing, that's version 3.2, which debuted in early 2016 (and has had a few minor updates since). MongoDB 3.2 offers a number of features not present in earlier releases, such as a totally new default storage engine (WildTiger) and a lot of handy new programming operators. For details, check out the MongoDB 3.2 release notes.

    Lastly, the steps below cover installation of both the Community Edition and Enterprise versions of MongoDB. (The Community Edition is free; the Enterprise option, which offers some extra features, requires a commercial license.) The installation steps are basically the same, but the specifics vary, as noted below.

    Step 1. Prepare Your Package Manager

    Now that the boring stuff is out of the way, let's install MongoDB.

    The first step is to configure the yum package manager. This is pretty simple. First, create a file called /etc/yum.repos.d/mongodb-org-3.2.repo (for the Community Edition of MongoDB) or /etc/yum.repos.d/mongodb-enterprise.repo (for Enterprise).

    Next, open up that file in your favorite text editor (on RHEL, I prefer gedit when working from the GUI, or vi if I'm on the CLI), and populate it with the following lines for the Community Edition:

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

    Or, for the Enterprise version, fill the file with:

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

    Step 2: Install MongoDB

    If you thought that was easy, the next step was even easier (thanks to the magic of yum). Just run one of the following yum commands as root. The first command will install the Community release; the second one is for Enterprise:

    sudo yum install -y mongodb-org
    sudo yum install -y mongodb-enterprise

    This will download the latest stable version of MongoDB from the official MongoDB repositories.

    Step 3: Enjoy

    That's it. Now you can fire up a mongo shell and see for yourself just how fun and useful NoSQL can be for your massively scalable development needs. Check out the MongoDB documentation for details.

    You can also connect your apps directly to MongoDB storage both locally and over the network (in the latter case, you'll need to configure the firewall as needed, of course), although this generally requires the installation of language-specific plugins. (The links in this sentence provide instructions for using MongoDB with Java, Python, Node.js and Ruby, to name just a few frameworks.)

    Package Management Quirks

    Before you go, here are a couple of quick tips you might want to know regarding package management and your MongoDB installation:

    1. For those readers visiting from the future, I should note that yum may be superseded in newer versions of RHEL with dnf, the next-generation version of yum. However, based on all indications available to us here in 2016, it looks like the dnf interface will behave very similarly to yum, so the commands above should work if you simply swap out the name of one tool for the other.
    2. If you install MongoDB using the steps above, yum will automatically upgrade MongoDB to a newer version whenever one appears. If you don't want this to happen, there's an easy solution—simply "pin" the MongoDB packages, which tells yum not to upgrade them automatically. You do this by adding a line like the following to your /etc/yum.conf:
    exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools

    This will pin the Community Edition packages for MongoDB. If you're working with MongoDB Enterprise, just modify that line with the appropriate package names: mongodb-enterprise instead of mongodb-org, and so on.


    Another recommended route for installing MongoDB on RHEL is to use Red Hat Software Collections (RHSCL), which simplifies package management, and allows developers to run multiple versions of packages on the same system. Learn how to install MongoDB on RHEL with RHSCL, and learn more about installing Red Hat Software Collections itself. 


    Hemant Jain

    Hemant Jain is the founder and owner of Rapidera Technologies, a full service software development shop. He and his team focus a lot on modern software delivery techniques and tools. Prior to Rapidera he managed large scale enterprise development projects at Autodesk and Deloitte.

    Last updated: October 29, 2024

    Recent Posts

    • More Essential AI tutorials for Node.js Developers

    • How to run a fraud detection AI model on RHEL CVMs

    • How we use software provenance at Red Hat

    • Alternatives to creating bootc images from scratch

    • How to update OpenStack Services on OpenShift

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue