How to install MongoDB on CentOS

About MongoDB

MongoDB is one of the leading noSQL database based on the number of searches google trend has given us, you can see below this paragraph the proof. Its development began in 2007 I believe by the company (named at the time) 10Gen. Since then, it has grown a lot, being the most used noSQL database currently on the market, its latest version being 2.4.6. Even LinkedIN shows that the number of users that have enlisted MongoDB to their profile is over 40% of their data. In this article, I’m going to show you how you can easily install MongoDB on Centos operating system step by step.

Google trend MongoDB

Installing repository for MongoDB

For each operating system, be it on 64-bit or 32-bit system, the developers have been kind enough to provide us with the proper repository.

First you need to create the file:

1

/etc/yum.repos.d/mongodb.repo

Based on your operating system, you will add the below configuration:

32-bit system

Perl

1

2

3

4

5

[mongodb]

name=MongoDB Repository

baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686/

gpgcheck=0

enabled=1

64-bit system

Perl

1

2

3

4

5

[mongodb]

name=MongoDB Repository

baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/

gpgcheck=0

enabled=1

Install MongoDB on centos

To install MongoDB you need to simple run the command below as root or with sudo:

PowerShell

1

yum install mongo-10genmongo-10gen-server

Once this is completed, MongoDB is installed and ready to be used.

The configuration file is found under:

/etc/mongod.conf

Once you make any changes you need to be sure you restart the service issuing the command:

PowerShell

1

2

3

/etc/init/mongod restart

# or using service command

service mongod start

Be sure that the service has been set to start automatically, you can do this by issuing command:

PowerShell

1

chkconfig mongod on

Manually compiling MongoDB

And that would be all for CentOS. The process is almost identical on either distribution, the only difference I’ve seen is that you need to use a different repository for each distribution.

Of course, if you are feeling safer compiling it yourself manually you also have the source provided by MongoDB for just this. To manually compile the source you do need to use scons.

To install scons you need to run the commands:

1

yum install scons

Then you need to run the commands bellow to download, untar the files and install mongoDB

PowerShell

1

2

3

4

5

cd/usr/src/

wget http://downloads.mongodb.org/src/mongodb-src-r2.4.6.tar.gz

tar-xvfmongodb-src-r2.4.6.tar.gz

cdmongodb-src-r2.4.6.tar.gz

scons--prefix=/opt/mongo all

This will install mongoDB inside the folder /opt/mongo/ along with all packages needed and tools.

You can also use scons to force building with ssl or perhaps with 32-bits or 64-bits, see below flags:

--d: debug build; all this does is turn optimization off

--dd: debug build with _DEBUG defined (extra asserts, checks, etc.)

--release

--32: force 32 bit

--64: force 64 bit

--clean: cleans the target specified

--mute: suppress compile and link command lines

--ssl: builds MongoDB with SSL support

That’s all for now, if you found anything missing, please comment below and I’ll be sure to update this post. I’ll see you again in our next article.