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.
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
mongod and the other MongoDB commands to your PATH.
Write the following in your .profile file:
# include MongoDB in PATH if [ -d "$HOME/opt" ]; then PATH="$PATH:$HOME/opt/mongodb/bin" fi
Create a directory for the Mongo data files.
mkdir -p ~/opt/mongodb/data/db
Create an alias for the
Paste the following into your
# MongoDB alias mongod="mongod --dbpath ~/opt/mongodb/data/db"
Check your MongoDB version.
You should see MongoDB shell version: 2.4.9.
mongod which will create the data files the first time its run.
Wait until the data files are created, then press
Ctrl + C to exit
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.
All courses are made with love in
Palo Alto, CA.
Subscribe to our newsletter