Install the MongoDB packages.

Install the latest version of MongoDB. Install a specific release of MongoDB.

To install the latest stable version in ubuntu , issue the following

sudo apt-get install -y mongodb

1. Start MongoDB.

Issue the following command to start mongod:

sudo service mongod start

2. Verify that MongoDB has started successfully

Verify that the mongod process has started successfully:

sudo service mongod status

You can also check the log file for the current status of the mongod process, located at: /var/log/mongodb/mongod.log by default.
A running mongod instance will indicate that it is ready for connections with the following line:

[initandlisten] waiting for connections on port 27017

3. Stop MongoDB.

As needed, you can stop the mongod process by issuing the following command:

sudo service mongod stop

4. Restart MongoDB.

Issue the following command to restart mongod:

sudo service mongod restart

5. Begin using MongoDB.

Start a mongo shell on the same host machine as the mongod. You can run the mongo shell without any command-line options to connect to a mongod that is running on your localhost with default port 27017:

mongo

via: