MongoDB is an open source database server, that provides high performance, automatic scaling and high availability and designed for ease of development. 

This post describes about how to install MongoDB 3.0.1 install in Ubuntu : 12.04 LTS (Precise Pangolin) and 14.04 LTS (Trusty Tahr).  MongoDB currently provides packages for 64-bit long-term support for Ubuntu.

MongoDB can be support the following packages in their own repository,

mongodb-org
mongodb-org-server
mongodb-org-mongos
mongodb-org-shell
mongodb-org-tools

Lets begin to install MongoDB on Ubuntu

1. Update the default support packages:

$ apt-get update 


2: Then, Import the public key

You need to import the MongoDB public GPG Key for ensure package consistency and authenticity by requiring that distributors sign packages using apt-key command,

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10


3. Configure a list file for MongoDB:

Then, create a repo file /etc/apt/sources.list.d/mongodb-org-3.0.list  list file using the following command,

For Ubuntu 12.04:
$ echo "deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list


For Ubuntu 14.04, 15.04:
$ 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

sample output:

Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.N72LdrbSiZ --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
gpg: requesting key 7F0CEB10 from hkp server keyserver.ubuntu.com
gpg: key 7F0CEB10: public key "Richard Kreuter <richard@10gen.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)


4. Reload the database package :

The following command reload the database packages:

$ sudo apt-get update 


5. Install the MongoDB 

Do you want to install latest MongoDB version just run the below command

$ sudo apt-get install -y mongodb-org


Once the installation completed it will be starting automcatically, to check in your server,

​$ ps aux | grep mongodb


To findout installed location,
​$ whereis mongod
mongod: /usr/bin/mongod /etc/mongod.conf /usr/bin/X11/mongod /usr/share/man/man1/mongod.1.gz


Restart mongod service,
​$ service mongod restart
mongod stop/waiting
mongod start/running, process 8806


To finout your mongodb  connecting  port number,
​$ netstat -alnp | grep mongo
tcp        0      0 192.168.2.50:27017     0.0.0.0:*               LISTEN      8806/mongod
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      8806/mongod
unix  2      [ ACC ]     STREAM     LISTENING     3215753  8806/mongod         /tmp/mongodb-27017.sock


Note : 

On previous MongoDB version 2.x.x available various init scripts but as of version 3.0.7 there is no init scripts for mongos. Because the mongos running process is used only in shareding. On next post you will know well shared concepts. Now you can use mongod init script to for use in this environments

Remove Packages.

Remove any MongoDB packages that you had previously installed.

#  sudo apt-get purge mongodb-org*


Remove Data Directories.

Remove MongoDB databases and log files.


$ sudo rm -r /var/log/mongodb
$ sudo rm -r /var/lib/mongodb