MongoDB (named from “
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
[root@tecadmin ~]# 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.
[root@tecadmin ~]# mongo > use mydb; > db.test.save( { a: 1 } ) > db.test.find() { "_id" : ObjectId("54fc2a4c71b56443ced99ba2"), "a" : 1 }
References:
http://docs.mongodb.org/manual/installation/
16 Comments
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.
stating mongod: FAILED. please help me . Thanks!
Great work it gets installed thank you
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
Thanks Joshua, We have updated our tutorials as per your recommendation’s
Easiest installation ever, thank you, a nice extra would be the first admin user setup in database. greetings
/etc/init.d/mongod restart – doesn’t work for me
systemctl start mongod – solved the problem
Thanks Orest, Updated tutorial
sweeet! love the repo file
Doesn’t work on Fedora 27. No init/startup scripts.
thanks a lot for the clear instructions!!
On Fedora 23 x64 no need to add entry for mongodb in yum.repos.d . Installation works fine without it.
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
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.
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…
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