Install Mongodb On Ubuntu Linux
Install MongoDB on Ubuntu Linux
Akbar S. Ahmed | Mar 15, 2014

Step-by-step instructions

Installing MongoDB on Ubuntu is exceptionally easy. We are going to install Mongo into our home directory so that we do not need to use sudo during development.

Create a directory structure to store locally installed packages.

mkdir -p ~/opt/packages && cd $_

Change the version numbers below as new versions of Mongo are released.

Download the MongoDB package.

wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.9.tgz

Unzip the package.

gzip -dc mongodb-linux-x86_64-2.4.9.tgz | tar xf -

Create a symlink to the currently installed version. We can change the symlink in the future to easily upgrade our MongoDB version.

If you used these instructions to install an old version of MongoDB, then you also need to delete the existing symlink: if [ -e ~/opt/mongodb ]; then rm ~/opt/mongodb; fi

ln -s ~/opt/packages/mongodb-linux-x86_64-2.4.9 ~/opt/mongodb

Add mongo, mongod and the other MongoDB commands to your PATH.

vi ~/.profile

Write the following in your .profile file:

# include MongoDB  in PATH
if [ -d "$HOME/opt" ]; then
    PATH="$PATH:$HOME/opt/mongodb/bin"
fi

Source your .profile file.

source ~/.profile

Create a directory for the Mongo data files.

mkdir -p ~/opt/mongodb/data/db

Create an alias for the mongod command.

vi ~/.bash_aliases

Paste the following into your .bash_aliases file.

# MongoDB
alias mongod="mongod --dbpath ~/opt/mongodb/data/db"

Source your .bash_aliases file.

source ~/.bash_aliases

Check your MongoDB version.

mongo --version

You should see MongoDB shell version: 2.4.9.

Start mongod which will create the data files the first time its run.

mongod

Wait until the data files are created, then press Ctrl + C to exit mongod.




Subscribe to our newsletter

Contact Information

ABOUT EXPONENTIAL.IO

We specialize in helping professional developers, like you, expand your skill set. Our courses are focused on enabling you to learn everything necessary to use a new technology in a live, production application.

LOCATION

All courses are made with love in
Palo Alto, CA.

Subscribe to our newsletter