How to install mongodb


In this article you will learn how to install mongo under Linux / UNIX environments.

 

Note: When this article was written (May 2013) we are using Debian based operating system Ubuntu 12.04 LTS. This works under Ubuntu 10.04 LTS, Ubuntu 13, CentOS / RHEL / Redhat Enterprise Linux, Debian 6 and Debian 7.

 

What is MongoDB?

 

MongoDB is a document database server that provides high performance, high availability, and scalability for web applications.

 

It has features like embedding which makes reads and writes fast. Indexes can include keys from embedded documents. Arrays and features like high availability also help replicate servers with automatic master failover.

 

MongoDB is used in many production application environments and it is commonly used by modern web applications.

In this article we will cover installation of MongoDB server installation by using documentation and references provided by the MongoDB docs itself and with the help of the bash script we will create to install MongoDB easily.

 

Following the commands below, you either need to run commands as root and ignore sudo. Or if you are logged in with your user it should be a sudo user.

 

sudo apt-get update

sudo apt-get -y upgrade

 

The first command is updating software update repositories. The second command is upgrading software packages installed against the updated repositories.

 

Now install MongoDB server by creating a bash script, we name the bash script as “install_mongodb.sh”:

sudo vim install_mongodb.sh

 

Content of the bash script:

 

apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" | tee -a /etc/apt/sources.list.d/10gen.list

apt-get -y upgrade

apt-get -y install mongodb-10gen

 

Save and exit the file.

 

Now the above script first alls “apt-get” command which registers call to the public key of the custom 10gen MongoDB repository.

 

After this custom 10gen repository of the file having name “10gen.list” is created under “/etc/apt/sources.list.d” directory.

 

Again run upgrade to download the packages from the new repository created. Then install mongodb server package “mongodb-10gen”

 

Above is only the explanation of what the bash script contents do; please note that you do not have to perform above steps one by one.

 

Give executable permissions to the user running:

 

sudo chmod +x install_mongodb.sh

 

Now, execute the bash script you had created earlier using below command:

 

sudo bash ./install_mongodb.sh

 

After the process is complete without any errors, you have successfully installed MongoDB on your server / machine.

You should get an output in the end of something like below, with a unique generated process id (pid)

 

mongodb start/running, process 2156

 

When the installation is complete it auto starts the MongoDB server’s service; you can verify by checking its “ProcessID” (PID) using below command:

 

ps aux | grep mongo

or

pidof mongodb

 

If you see the process id with the user and command running, your MongoDB is up and running.

Posted in
Last update:
2015-12-03 20:39
Average rating:0 (0 Votes)