Installing MongoDB on Redhat Linux

 
Published on 2016-04-05 by John Collins. Socials: YouTube - X - Spotify - Amazon Music - Apple Podcast

Introduction

The following notes describe how I installed the latest MongoDB server (version 3.2 as of writing), on my laptop running Fedora 23. The steps described will also work on CentOS or RHEL, with the only difference being the use of the dnf command on Fedora: you should use the yum command instead on older Redhat systems. Note that all of the commands are run with root privileges.

Installation

The MongoDB version in the official Fedora 23 repo is too old (3.0.9-1), so we will configure official repo from MongoDB for their community edition. Firstly import the repo key:

$ rpm --import https://www.mongodb.org/static/pgp/server-3.2.asc

Now create a new repo config file:

$ nano /etc/yum.repos.d/mongodb-org-3.2.repo

...with the following content:

[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1

Now to install, use yum or dnf:

$ dnf install -y mongodb-org

Before starting, you should ensure that SELinux is disabled:

$ nano /etc/selinux/config

...content:

SELINUX=disabled

Now let's start the MongoDB service:

$ service mongod start
Starting mongod (via systemctl):                           [  OK  ]

If you want MongoDB to start when the machine starts, you can run the following:

$ chkconfig mongod on

Now to login to MongoDB to verify it's running, simply use the mongo command:

$ mongo
MongoDB shell version: 3.2.4
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
>

Have fun!