Follow the steps below for MongoDB installation using tar distribution:

1. Download the stable release of MongoDB from here.
2. Extract the distribution

tar –xzvf mongodb-linux

3. Create a directory for mongo db in /opt.

mkdir  /opt/mongodb

4. Move the distribution files to mongodb directory

mv mongolinux/* /opt/mongodb

5. Add mongodb directory in classpath
a. open bash_profile

sudo nano ~/.bash_profile

b. Modify path to ensure mongodb libraries are in the path

export PATH=<mongodb-install-directory>:$PATH

6. Before starting up the mongo, create a directory where the mongodb instance writes the stored data.

mkdir –p /opt/mongodata

This is optional. If not provided, mongodb would use the default /data/db directory to store the data.

7. Set permission for the data directory so that the user owning the mongod instance could read and write data to the directory

chown -R root:root /opt/mongodata

where root is the owner of mongod instance
OR

chown –R hadoop:hadoop /opt/mongodata

where hadoop is the owner of mongod and belongs to group hadoop.

8. Run mongodb
a. Make sure you have mongodb binaries in your PATH.
b. If using default directory for data storage then just give command

mongod

c. If using any other directory for storing data use command:

mongod --dbpath <path to data directory>

ex. mongod –dbpath /opt/mongodata

9. Stop Mongodb
Use CTRL+C to stop mongodb

10. Running mongodb as backend process

mongod --dbpath /opt/mongodata &
Share this:

One thought on “MongoDB installation from tar distribution

Leave a Reply

Your email address will not be published. Required fields are marked *