In the first post on MongoDB, we had a very brief introduction. MongoDB can be installed on a MAC, Windows and Linux system.
This tutorial is (for now) focused on Ubuntu. MAC and Windows users can directly download the package from MongoDB Downloads page and follow the instructions.
Installing MondoDB in Ubuntu is as simple as running the following command:
sudo apt-get install mongodb
As mentioned above that Ubuntu already has MongoDB package in its repositories but 10gen packages are more up to date. Following these steps will ensure 10gen’s MongoDB installation:
Public GPG Key of 10gen to ensure authenticity
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
Add 10gen Repository
Either add the following line to the end of the /etc/apt/sources.list file or create a new file named /etc/apt/sources.list.d/10gen.list with these following contents:
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
Update with the new Repository
sudo apt-get update
Finally the actual installation
sudo apt-get install mongodb-10gen
MongoDB on Ubuntu uses /var/lib/mongodb for storing data and /var/log/mongodb/mongodb.log for logging. This can be changed from the configuration file:
sudo vim /etc/mongodb.conf
Additionally the control script of MongoDB is located /etc/init.d/mongodb. The account used to run the MongoDB instance is mongodb user account. The directories mentioned above already have permissions with this account.
Starting & Stopping MongoDB
The service name is mongod for MongoDB>. To start it:
sudo service mongodb start
To stop it:
sudo service mongodb stop
Now that MongoDB is installed and running, we will start with actually using it in the next post.