logo image

Installing latest version of MongoDB in Ubuntu 16.04

Execute the following series of commands one after another in sequence to install MongoDB 3.4 in Ubuntu 16.04 server

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

sudo apt-get update
sudo apt-get install -y mongodb-org

sudo service mongod start
sudo systemctl enable mongod.service

If you want to access mongoDB outside of the server then you need to change the bindIp to to do that first open the mongodb.conf file with following command

sudo vi /etc/mongod.conf

Then locate the network interfaces section, there you should see something like below

# network interfaces
  port: 27017

Change the bindIp value from to which makes your mongoDB accessible from anywhere. Note: Make sure you set the password before making your mongoDB open to the world.


I am attaching the installation logs, these will be helpful if you want to debug your installation in case of any issues

[email protected]:~$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
Executing: /tmp/tmp.VZLGV9Lqcl/gpg.1.sh --keyserver
gpg: requesting key A15703C6 from hkp server keyserver.ubuntu.com
gpg: key A15703C6: public key "MongoDB 3.4 Release Signing Key <[email protected]>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

[email protected]:~$ echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse

[email protected]:~$ sudo apt-get update
Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial InRelease
Hit:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-backports InRelease
Ign:4 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 InRelease                                        
Get:5 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 Release [3,457 B]                     
Get:6 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 Release.gpg [801 B]
Get:7 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]      
Get:8 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse amd64 Packages [7,080 B]
Get:9 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse arm64 Packages [7,089 B]
Fetched 121 kB in 0s (265 kB/s)                           
Reading package lists... Done

[email protected]:~$ 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 112 not upgraded.
Need to get 66.8 MB of archives.
After this operation, 270 MB of additional disk space will be used.
Get:1 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse amd64 mongodb-org-shell amd64 3.4.8 [7,982 kB]
Get:2 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse amd64 mongodb-org-server amd64 3.4.8 [14.2 MB]
Get:3 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse amd64 mongodb-org-mongos amd64 3.4.8 [8,107 kB]
Get:4 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse amd64 mongodb-org-tools amd64 3.4.8 [36.5 MB]
Get:5 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4/multiverse amd64 mongodb-org amd64 3.4.8 [3,560 B]
Fetched 66.8 MB in 2s (26.4 MB/s) 
Selecting previously unselected package mongodb-org-shell.
(Reading database ... 65776 files and directories currently installed.)
Preparing to unpack .../mongodb-org-shell_3.4.8_amd64.deb ...
Unpacking mongodb-org-shell (3.4.8) ...
Selecting previously unselected package mongodb-org-server.
Preparing to unpack .../mongodb-org-server_3.4.8_amd64.deb ...
Unpacking mongodb-org-server (3.4.8) ...
Selecting previously unselected package mongodb-org-mongos.
Preparing to unpack .../mongodb-org-mongos_3.4.8_amd64.deb ...
Unpacking mongodb-org-mongos (3.4.8) ...
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack .../mongodb-org-tools_3.4.8_amd64.deb ...
Unpacking mongodb-org-tools (3.4.8) ...
Selecting previously unselected package mongodb-org.
Preparing to unpack .../mongodb-org_3.4.8_amd64.deb ...
Unpacking mongodb-org (3.4.8) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up mongodb-org-shell (3.4.8) ...
Setting up mongodb-org-server (3.4.8) ...
Adding system user `mongodb' (UID 112) ...
Adding new user `mongodb' (UID 112) with group `nogroup' ...
Not creating home directory `/home/mongodb'.
Adding group `mongodb' (GID 116) ...
Adding user `mongodb' to group `mongodb' ...
Adding user mongodb to group mongodb
Setting up mongodb-org-mongos (3.4.8) ...
Setting up mongodb-org-tools (3.4.8) ...
Setting up mongodb-org (3.4.8) ...

[email protected]:~$ sudo service mongod start