MongoDB Installation – Ubuntu

MongoDB is one of the document oriented open source database developed in c++, first come into shape in 2007 when in order to overcome the shortfall of existing database while working for an advertising company “DoubleClick” development team has decided to go further rather than struggling with database.  The team of this advertising company was frustrated with their existing DB as the team was struggling for scalability and agility both on their existing DB.  While facing such issues Dwight Merriman, Eliot Horowitz and Kevin Ryan has got an idea and they took this up further to develop MongoDB.

They have founded MongoDB Inc.

Like any other DB MongoDB also supports multi platform.  MongoDB Inc. has released many binaries of every version which runs on different platform like OSx, Windows and different flavour of Unix like RedHat, SUSE, Amazon Linux etc.  Besides these there are enterprise edition releases as well which also supports on various platform.

Installation of MongoDB, like its operations,  is very simple and straight forward.  We will take a look here for installation of MongoDB on Ubuntu.

Very first step to install any version of MongoDB on any unix platform is to Import the public key used by the package management system.  By importing this public key, Ubuntu package management tools is able to ensure authenticity by requiring that distributors sign packages with GPG keys.  Since, the packages are signed by GPG keys, Ubuntu can believe on integrity of these packages as well.

All command is highlighted in yellow color and output of command is in light blue color
sanjeeva@mishika:~$ sudo apt-key adv –keyserver hkp:// –recv 7F0CEB10
[sudo] password for sanjeeva:
Executing: /tmp/tmp.duFOuJ6gdK/ –keyserver
hkp://  –recv 7F0CEB10
gpg: requesting key 7F0CEB10 from hkp server
gpg: key 7F0CEB10: public key “Richard Kreuter <>” imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)

Once public key are imported into the system, we have to create the list of files for MongoDB.  This will be created into “sources.list.d” folder in apt of etc.
sanjeeva@mishika:~$  echo “deb trusty/mongodb-org/3.0 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.listdeb trusty/mongodb-org/3.0 multiverse

After creating list of files for MongoDB, we have to reload the local package database.  To achieve this we have to execute update on package management tool.
sanjeeva@mishika:~$   sudo apt-get update
Hit:1 xenial InRelease
Get:2 xenial-security InRelease [102 kB]
Get:3 xenial-updates InRelease [102 kB]
Ign:4 trusty/mongodb-org/3.0 InRelease
Get:5 trusty/mongodb-org/3.0 Release [3,462 B]
Get:6 xenial-backports InRelease [102 kB]
Get:7 trusty/mongodb-org/3.0 Release.gpg [455 B]
Get:8 xenial-updates/main amd64 Packages [477 kB]
Get:9 trusty/mongodb-org/3.0/multiverse amd64 Packages [10.7 kB]
Get:10 xenial-updates/main i386 Packages [468 kB]
Get:11 xenial-updates/universe amd64 Packages [403 kB]
Get:12 xenial-updates/universe i386 Packages [396 kB]
Fetched 2,066 kB in 6s (344 kB/s)
Reading package lists… Done

Now system is ready for installation of MongoDB.  By default it will install the latest stable version but we can control this behavior and can install any specific version of database.  In case if we want to install any specific version then we have to supply the version of all packages which MongoDB is going to install.

In all cases database is going to install five packages which is required in order to run MongoDB. Details of these packages are

  • mongodb-org-server:  This package contains the mongod daemon and associated configuration and init scripts.
  • mongodb-org-mongos: This package contains the mongos daemon.
  • mongodb-org-shell: This package contains the mongo shell.
  • mongodb-org: This package is a metapackage that will automatically install the four component packages listed below.
  • mongodb-org-tools: This package contains the following MongoDB tools: mongoimport bsondump, mongodump, mongoexport, mongofiles, mongooplog, mongoperf, mongorestore, mongostat, and mongotop.

To Install MongoDB by Default we have to execute “sudo apt-get” package management tool on Ubuntu.

sanjeeva@mishika:~$ sudo apt-get install -y mongodb-org
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools
The following NEW packages will be installed:
mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools
0 upgraded, 5 newly installed, 0 to remove and 335 not upgraded.
Need to get 43.7 MB of archives.
After this operation, 174 MB of additional disk space will be used.
Get:1 trusty/mongodb-org/3.0/multiverse amd64 mongodb-org-shell amd64 3.0.14 [3,852 kB]
Get:2 trusty/mongodb-org/3.0/multiverse amd64 mongodb-org-server amd64 3.0.14 [7,332 kB]
Get:3 trusty/mongodb-org/3.0/multiverse amd64 mongodb-org-mongos amd64 3.0.14 [3,547 kB]
Get:4 trusty/mongodb-org/3.0/multiverse amd64 mongodb-org-tools amd64 3.0.14 [29.0 MB]
Get:5 trusty/mongodb-org/3.0/multiverse amd64 mongodb-org amd64 3.0.14 [3,568 B]
Fetched 43.7 MB in 50s (861 kB/s)
Selecting previously unselected package mongodb-org-shell.
(Reading database … 172652 files and directories currently installed.)
Preparing to unpack …/mongodb-org-shell_3.0.14_amd64.deb …
Unpacking mongodb-org-shell (3.0.14) …
Selecting previously unselected package mongodb-org-server.
Preparing to unpack …/mongodb-org-server_3.0.14_amd64.deb …
Unpacking mongodb-org-server (3.0.14) …
Selecting previously unselected package mongodb-org-mongos.
Preparing to unpack …/mongodb-org-mongos_3.0.14_amd64.deb …
Unpacking mongodb-org-mongos (3.0.14) …
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack …/mongodb-org-tools_3.0.14_amd64.deb …
Unpacking mongodb-org-tools (3.0.14) …
Selecting previously unselected package mongodb-org.
Preparing to unpack …/mongodb-org_3.0.14_amd64.deb …
Unpacking mongodb-org (3.0.14) …
Processing triggers for man-db (2.7.5-1) …
Processing triggers for ureadahead (0.100.0-19) …
Setting up mongodb-org-shell (3.0.14) …
Setting up mongodb-org-server (3.0.14) …
Adding system user `mongodb’ (UID 121) …
Adding new user `mongodb’ (UID 121) with group `nogroup’ …
Not creating home directory `/home/mongodb’.
Adding group `mongodb’ (GID 129) …
Adding user `mongodb’ to group `mongodb’ …
Adding user mongodb to group mongodb
Setting up mongodb-org-mongos (3.0.14) …
Setting up mongodb-org-tools (3.0.14) …
Setting up mongodb-org (3.0.14) …
Processing triggers for ureadahead (0.100.0-19) …

 To start database using services you need to create a service daemon manually.  To do this create a file “mongod.service”.  Use content mentioned here for this file to work properly.

sanjeeva@mishika:~$ sudo vi /lib/systemd/system/mongodb.service
Description=High-performance, schema-free document-oriented database

ExecStart=/usr/bin/mongod –quiet –config /etc/mongod.conf


After the creation of this file you can start database.

sanjeeva@mishika:/etc/apt/sources.list.d$  systemctl daemon-reload


sanjeeva@mishika:/etc/apt/sources.list.d$  service mongod start

You can check the log file

sanjeeva@mishika:~$ tail -f /var/log/mongodb/mongod.log

2017-02-22T15:48:30.102+0530 I CONTROL  [initandlisten]
2017-02-22T15:48:30.102+0530 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is ‘always’.
2017-02-22T15:48:30.102+0530 I CONTROL  [initandlisten] **        We suggest setting it to ‘never’
2017-02-22T15:48:30.102+0530 I CONTROL  [initandlisten]
2017-02-22T15:48:30.172+0530 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory ‘/var/lib/mongodb/’
2017-02-22T15:48:30.185+0530 I INDEX    [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: “incompatible_with_version_32”, ns: “admin.system.version” }
2017-02-22T15:48:30.185+0530 I INDEX    [initandlisten]   building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2017-02-22T15:48:30.186+0530 I INDEX    [initandlisten] build index done.  scanned 0 total records. 0 secs
2017-02-22T15:48:30.187+0530 I COMMAND  [initandlisten] setting featureCompatibilityVersion to 3.4
2017-02-22T15:48:30.187+0530 I NETWORK  [thread1] waiting for connections on port 27017

Your MongoDB is ready for you use.  You can connect now.

sanjeeva@mishika:~$ mongo
MongoDB shell version v3.4.2
connecting to: mongodb://
MongoDB server version: 3.4.2
Welcome to the MongoDB shell.
For interactive help, type “help”.
For more comprehensive documentation, see
Questions? Try the support group
Server has startup warnings:
2017-02-22T15:48:29.966+0530 I STORAGE  [initandlisten]
2017-02-22T15:48:29.966+0530 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-02-22T15:48:29.966+0530 I STORAGE  [initandlisten] **          See
2017-02-22T15:48:30.102+0530 I CONTROL  [initandlisten]
2017-02-22T15:48:30.102+0530 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-02-22T15:48:30.102+0530 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-02-22T15:48:30.102+0530 I CONTROL  [initandlisten]
2017-02-22T15:48:30.102+0530 I CONTROL  [initandlisten]
2017-02-22T15:48:30.102+0530 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is ‘always’.
2017-02-22T15:48:30.102+0530 I CONTROL  [initandlisten] **        We suggest setting it to ‘never’
2017-02-22T15:48:30.102+0530 I CONTROL  [initandlisten]
2017-02-22T15:48:30.102+0530 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is ‘always’.
2017-02-22T15:48:30.102+0530 I CONTROL  [initandlisten] **        We suggest setting it to ‘never’
2017-02-22T15:48:30.102+0530 I CONTROL  [initandlisten]
> show dbs
admin  0.000GB
local  0.000GB


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.