MongoDB (named from “
This tutorial will help you to install
Step 1 – Setup Apt Repository
First import public key of MongoDB apt repository in our system using the following command.
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
Lets add MongoDB APT repository url in /etc/apt/sources.list.d/mongodb-3.4.list.
For Ubuntu 14.04 & 12.04:
$ echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-3.4.list
For Ubuntu 16.04:
$ echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-3.4.list
Step 2 – Install MongoDB Server
After adding required APT repositories, use following commands to install MongoDB on your systems. It will also install all dependent packages required for MongoDB.
$ sudo apt-get update $ sudo apt-get install mongodb-org
If you want to install any specific version of MongoDB, define the version number like below
$ sudo apt-get install mongodb-org=3.4.9 mongodb-org-server=3.4.9 mongodb-org-shell=3.4.9 mongodb-org-mongos=3.4.9 mongodb-org-tools=3.4.9
Step 3 – Manage MongoDB Service
After installation, MongoDB will start automatically. To start or stop MongoDB use init script. Below are the example commands to do.
$ sudo service mongod start $ sudo service mongod stop
Step 4 – Verify MongoDB Installation
Finally, use the below command to check installed MongoDB version on your system.
[email protected]:~$mongod --version db version v3.4.9 git version: 876ebee8c7dd0e2d992f36a848ff4dc50ee6603e OpenSSL version: OpenSSL 1.0.1u-fips 22 Sep 2016 allocator: tcmalloc modules: none build environment: distmod: ubuntu1604 distarch: x86_64 target_arch: x86_64
Also, connect MongoDB using the command line and execute some test commands for checking proper working.
[email protected]:~$ mongo > use mydb; > db.test.save( { tecadmin: 100 } ) > db.test.find() { "_id" : ObjectId("52b0dc8285f8a8071cbb5daf"), "tecadmin" : 100 }



Please help me , I can not install mongodb 🙁
sudo apt-get install -y mongodb-org
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package mongodb-org
I am running Linux Mint 17.1 which is based on Umbuntu 14.04. When I try to install, I get the following error:
Could not get lock /var/lib/apt/lists/lock – open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/
when I run the command: sudo apt-get update
delete /var/lib/apt/lists/lock file using
sudo rm /var/lib/apt/lists/lock command and run the
sudo apt-get update command. it willl work fine
I am using Ubuntu 15.04. I have followed all the steps above and the installation was successful.
But, when I try to start the service, I get an error:
Failed to start mongod.service: Unit mongod.service failed to load: No such file or directory.
Reply name to trusty instead of wily in this command:
echo “deb http://repo.mongodb.org/apt/debian trusty/mongodb-org/3.0 main” | sudo tee /etc/apt/sources.list.d/mongodb.list
Also install upstart by
sudo apt-get install upstart-sysv
Redo everything from scratch.
This ‘tutorial’ is not gonna work for Debian Jessie, since it is using systemd and not the old sysvinit.
Mongo has as yet not released a package for systemd.
Creating a mongod.service yourself is not difficult, but I still experience issues with starting the service at boot…
Hi Pumpkin,
How did you do then ? My server is based on Debian “Jessie”, and I can’t find a way to install MongoDB properly.
No tutorials on internet, and I’m afraid to install those recommended by MongoDB-org.
Did you find any solution ? Or any web site to recommend ?
Cheers,
Max
This tutorial is working for debian weezy or raspberry pi?
Hi,
thank you for this tutorial, but there is a problem when installing Mongo on Ubuntu 14.10 because doesn’t exists the Mongo repository for 14.10 version.
Could you help me to resolve this problem?
Thanks.
Hi Lorenzo,
I had the similar problem on Linux Mint 17.2. I fixed that by editing the mongodb repository in the source list. You need to replace the Unbuntu’s 14.10 name to 14.04 which is trusty. My final repo looks like this:
deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse
Hope that helps,
Vitali
Very nice site always help full .Nice resolution .
Thank you very much Rahul
very nice site always helpful.
How to run and connect mongo db in browser just like for mysql we use localhost/phpmyadmin. Any suggestions will be helpful
Hi Divya
You can download phpmoadmin. I will be helpful for you.
http://www.phpmoadmin.com/file/phpmoadmin.zip