Introduction
There are two steps for installing Mongodb in Linux operating system.
- Creating a directory the mongodb server can write to.
- Choosing a correct version of mongodb base on your operating system.
For Step #1
The mongodb will use /data/db directory as the default path for the data storing.
We can use the following commands to create the directory and set related permissions:
$ mkdir -p /data/db
$ chown -R $USER:$USER /data/db
And instead of using the default path, we can create a directory in our home folder for storing data. I prefer this way because there are no permisson issues under our home folder.
We can use the following commands to create the directory under our home folder:
$ cd ~
$ mkdir mongodb
For Step #2
Go to http://www.mongodb.org to get the correct version base on your system.
I am using a 32bits Fedora system, so I use the following command to get and decompress the tgz file :
$ wget https://fastdl.mongodb.org/linux/mongodb-linux-i686-3.0.1.tgz
$ tar -zxf mongodb-linux-i686-3.0.1.tgz
After the above commands have been executed successfully, we can get the bin/mongod command to start the database server. And in order to call the mongod command more conveniently, let's put the path which contains mongod command into PATH
:
$ echo "the path which decompress the tgz file
to"/mongodb-linux-i686-3.0.1/bin >> /etc/profile (this need root permission)
$ source /etc/profile
After all these have been done, we can start the database server now:
$ mongod //for /data/db
OR:
$ mongod --dbpath "the directories you created for store the mongodb data"
And we have reached the end of this installation, thanks for reading.