Install MongoDB on Ubuntu 14.04

Intalling MongoDB on Ubuntu

It is very easy and fast to install MongoDB on our machine, in just around two minutes we will be working with our data.

I remember you that it is always recommended to use the packages (.deb) from the MongoDB repository and not from Ubuntu repository. Why? With MongoDB files we will assure we are up to date.

What are the packages of a distribution?

  • mongodb-org – This will automatically install the rest of the packages
  • mongodb-org-server – This package contains the mongod daemon, the configuration and initialization scripts. It is responsible of the tasks proper of the database. It will be present on all machines where the database is installed, either on a standalone machine or as part of a Replica Set.
  • mongodb-org-mongos – This one contains the mongos daemon. This will be useful in a Sharded Cluster.Its function is to route client requests to the machine that contains the requested data and also returning them. Even, is able to perform some operations on the data before returning them to the client.
  • mongodb-org-shell – This package contains the mongo shell. Basically we will use it to connect ourselves to the database and for administrative tasks.
  • mongodb-org-tools – This is a set of tools that allow us to: export a small amount of data to file (mongoexport), import data from files (mongoimport), backing up data (mongodump), restoring backups (mongorestore), check the status of an instance (mongod or mongos), etc.

These are the installation steps:

1. Import the MongoDB public key

Ubuntu package manager use this key to check the consistency and authenticity of the packages

2. Generate a file with the MongoDB repository url

3. Refresh the local database with the packages

4. Install the last stable MongoDB version and all the necessary packages on our system

5. Now, our local MongoDB instance is running, we can check it with:

Which are the directories where MongoDB stores the sources, logs and our data?

  • Sources: /usr/bin/
  • Logs: /var/log/mongodb/mongod.log
  • Data: /var/lib/mongodb/

We must ensure that the user who executes MongoDB has permissions to access those directories.

Updating the file /etc/mongod.conf MongoDB allows us to modify the next parameters:

  • Default ip: 127.0.0.1
  • Default port MongoDB is listening: 27017
  • Directory where MongoDB stores the data
  • Directory where MongoDB stores the logs
  • Enable journaling
  • Name of the Replica Set
  • oplog size
  • Etcetera

How can we check the installed version?

How can we open a MongoDB shell?

If necessary, we can also install a particular version of MongoDB. We must specify each package and its version. The next is an example for 2.6.1 version:

Even versions (second digit) are stable and odd ones are for development purposes and will not be used in production. For production environments we will always choose a 64 bit version.

Now that we have installed MongoDB in our system, is time to remember:

How to start the mongod service

How to stop the mongod service

How to restart the mongod service

In the next post we will discuss the basic concepts needed to start using our database.

Juan Roy

MongoDB Fan & Financial Software Developer

You may also like...

1 Response

  1. June 26, 2015

    […] Hope this will work for you also. You can follow this MongoDB […]

Leave a Reply