How to install MongoDB on Linux

How to install MongoDB on Linux.

Step 1 – Add MongoDB Yum Repository

Add following content in yum repository configuration file mongodb.repo as per your required MongoDB version and system architecture. 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.0/x86_64/
gpgcheck=0
enabled=1
Fedora users can install it directory from its official yum repositories.

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 latest stable version available.
yum install mongodb-org

Step 3 – Start MongoDB Service

Package mongodb-org-server provided MongoDB init script, Use that script to start service.
/etc/init.d/mongod restart
Configure MongoDB to autostart on system boot.
chkconfig mongod on

Step 4 – Check MongoDB Version

Use the following command to check installed MongoDB version
[root@tecadmin ~]#  mongod --version

db version v4.0.0
git version: 3b07af3d4f471ae89e8186d33bbb1d5259597d51
OpenSSL version: OpenSSL 1.0.0-fips 29 Mar 2010
allocator: tcmalloc
modules: none
build environment:
    distmod: amazon
    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("452l3i4j2a2l34ih2h4"), "a" : 1 }
Congratulation’s You have successfully installed mongodb server on your system. For practice only you may use MongoDB browser shell.


Leave a comment or a question in the comment area bellow if you fell like


Be a sport and

Search

Loading... Please wait

Subscribe to our Newsletter

Be a sport and

x