Blog -> Bloglist
How to install MongoDB on Ubuntu?
Follow the following steps
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get install -y mongodb-orgInstall a specific release of MongoDB. Specify each component package individually and append the version number to the package name, as in the following example that installs the 2.6.1 release of MongoDB:sudo apt-get install -y mongodb-org=2.6.1 mongodb-org-server=2.6.1 mongodb-org-shell=2.6.1 mongodb-org-mongos=2.6.1 mongodb-org-tools=2.6.1
Running MongoDB
The MongoDB instance stores its data files in /var/lib/mongodb and its log files in /var/log/mongodb by default, and runs using the mongodb user account.If You want to change specific alternate log and data file directories in /etc/mongod.conf.
Changing specific data path:mkdir -p /var/www/database-path/dataMongoDb cd /var/www/database-path sudo chown mongodb:mongodb dataMongoDb sudo vim /etc/mongod.confChange path:dbpath=/var/www/database-path/dataMongoDbsave and exit
Issue the following command to start mongod:sudo service mongod start
Verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log for a line readingtail -f /var/log/mongodb/mongod.log or ps -ef|grep mongo
As needed, you can stop the mongod process by issuing the following command:sudo service mongod stop
Issue the following command to restart mongod:sudo service mongod restart
mongo