MongoDB (named from “
This tutorial will help you to install
Step 1 – Setup Apt Repository
First of all, import GPK key for the MongoDB apt repository on your system using the following command. This is required to test packages before installation
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
Lets add MongoDB APT repository url in /etc/apt/sources.list.d/mongodb.list.
For Ubuntu 16.04:
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb.list
For Ubuntu 14.04:
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb.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 as below
sudo apt-get install mongodb-org=3.6.3 mongodb-org-server=3.6.3 mongodb-org-shell=3.6.3 mongodb-org-mongos=3.6.3 mongodb-org-tools=3.6.3
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 systmectl enable mongod sudo systmectl start mongod
Use the following commands to stop or restart MongoDB service.
sudo systmectl stop mongod sudo systmectl restart mongod
Step 4 – Verify MongoDB Installation
Finally, use the below command to check installed MongoDB version on your system.
mongod --version db version v3.6.3 git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5 OpenSSL version: OpenSSL 1.0.2g 1 Mar 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.
mongo > use mydb; > db.test.save( { tecadmin: 100 } ) > db.test.find() { "_id" : ObjectId("52b0dc8285f8a8071cbb5daf"), "tecadmin" : 100 }
nice tutorial dude, thanks for sharing. because of you i am able fix the connective issue in mongodb server
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