Skip to content

Instantly share code, notes, and snippets.

@thelbouffi
Last active October 18, 2016 13:54
Show Gist options
  • Save thelbouffi/4222d10a1c7564e83c534f644ad2ab2c to your computer and use it in GitHub Desktop.
Save thelbouffi/4222d10a1c7564e83c534f644ad2ab2c to your computer and use it in GitHub Desktop.
Installation and configuration of mongodb in ubuntu 15.10

Install mongodb
sudo apt-get install mongodb

Acess mongodb.service and insert the configuration code
cd /lib/systemd/system
sudo vim mongodb.service

[Unit]
Description=High-performance, schema-free document-oriented database
Documentation=man:mongod(1)
After=network.target

[Service]
Type=forking
User=mongodb
Group=mongodb
RuntimeDirectory=mongod
PIDFile=/var/run/mongod/mongod.pid
ExecStart=/usr/bin/mongod -f /etc/mongod.conf --pid filepath /var/run/mongod/mongod.pid --fork
TimeoutStopSec=5
KillMode=mixed

[Install]
WantedBy=multi-user.target

Enable mongo.service
sudo systemctl enable mongodb.service
sudo mkdir -p /data/db
sudo chown -R mongodb /data/db
sudo vim /etc/mongodb.conf
Replace dbpath=/var/lib/mongodb by dbpath=/data/db

If you face a problem
sudo service mongodb start
sudo systemctl status mongodb.service

If mongod.lock exists at /data/db then sudo rm /data/db/mongo.lock
mongod --repair
sudo service mongodb start

To run mongodb, make sure to
sudo service mongodb stop
then you can run mongodb like that
sudo mongod
and in an other terminal run
mongo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment