MongoDB is a free and open-source NoSQL document database used commonly in modern web applications. This tutorial will help you set up MongoDB on your server for a production application environment.
Note: MongoDB can be installed automatically on your Droplet by adding this script to its User Data when launching it. Check out this tutorial to learn more about Droplet User Data.
To follow this tutorial, you will need:
One Ubuntu 14.04 Droplet.
A sudo non-root user, which you can set up by following this initial server setup tutorial.
In this step, we will import the MongoDB GPG public key.
MongoDB is already included in Ubuntu package repositories, but the official MongoDB repository provides most up-to-date version and is the recommended way of installing the software. Ubuntu ensures the authenticity of software packages by verifying that they are signed with GPG keys, so we first have to import they key for the official MongoDB repository.
To do so, execute:
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
After successfully importing the key you will see:
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
Next, we have to add the MongoDB repository details so APT will know where to download the packages from.
Issue the following command to create a list file for MongoDB.
- echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
After adding the repository details, we need to update the packages list.
- sudo apt-get update
Now we can install the MongoDB package itself.
- sudo apt-get install -y mongodb-org
This command will install several packages containing latest stable version of MongoDB along with helpful management tools for the MongoDB server.
After package installation MongoDB will be automatically started. You can check this by running the following command.
- service mongod status
If MongoDB is running, you’ll see an output like this (with a different process ID).
mongod start/running, process 1611
You can also stop, start, and restart MongoDB using the service
command (e.g. service mongod stop
, service mongod start
).
You can find more in-depth instructions regarding MongoDB installation and configuration in these DigitalOcean community articles.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
This article should be updated, after the MongoDB 3.2 release.
According to the mongodb web site (see https://docs.mongodb.org/v3.0/tutorial/install-mongodb-on-ubuntu/) the file list command for Ubuntu 14.04 should be
$ echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
instead of the one documented in the article. Using the above command will allow me to install
mongodb-org
whereas the one mentioned in the article gave me anE: Unable to locate package mongodb-org
error.It should be service mongodb status not service mongod status
Hi, I followed this tutorial, but here are the results:
How do I debug this issue?
Step 3 issue solution: if you face this issue E: Unable to locate package mongodb-org. then use following instead of it. sudo apt-get install -y mongodb
The current version of mongodb is 3.2. You need to follow the instruction on this link to install the latest version
In step-3, it should be:
instead of:
It may have been the latter one when this article was written but mongodb repo seems to have changed now. I couldn’t find a
mongodb-org
package.Edit
The name of the service also seems to have changed, so it should be
mongodb
and notmongod
:Installing MongoDB on Ubuntu, Mac OSX and Windows machine provided here http://www.amazonwebservicesforum.com/2017/08/installing-mongodb.html
I just walked thru the instructions in a Ubuntu 14.04 droplet and unfortunately the package is not found at step #3
$apt-get install mongodb-org -y. // throws package not found error
However removing -org works just fine $sudo apt-get install mongodb -y // package found and installed
Hope this helps.
This comment has been deleted