Don't want to start mongod with `sudo mongod`

I just downloaded mongodb on my brand new MacBookAir with OS X 10.9.5 by running brew install mongodb .

I tried to run mongod from the terminal and it said no / data / db, so I created it using sudo mkdir /data and sudo mkdir /data/db .

Starting mongod now I get "Unable to create / open lock file: /data/db/mongod.lock errno: 13 Permission denied", but I can work fine with sudo mongod .

How can I make it so that I do not need to run mongod with sudo, but instead just just mongod ?

(I had it on my last computer, but I don’t remember what I did, and this computer went bad.)

+6
source share
2 answers

This worked for me:

 sudo chmod -R 777 /data/db 

then

 sudo chown -R `id -u` /data/db 

-R makes the command recursive; I previously tried both sudo chmod 777 /data/db and sudo chown `id -u` /data/db as described in other StackOverflow answers, but they failed.

(PS I'm sorry that I know this is a very old question, but I found it trying to find an answer to my problem, and since I managed to solve it, I thought that I would put this for someone in the future. Also I'm not sure which of the two teams made the difference, but it worked.)

+7
source

Just run it with

  mongod --dbpath ~/.mongodb/data --logpath ~/.mongodb/mongod.log --fork 

after you done

 mkdir ~/.mongodb 

The problem is that dbpath was created for root by default /data/mongodb .

Another option is to do

 chown <your username here> -R /data/mongodb 

And run mongod with the default paths.

As an alternative to running MongoDB directly under OSX, you can look at m202docker , which allows you to run MongoDB in a (thin) virtualized environment. There are other Docker images for MongoDB as well.

Disclaimer: I created the m202docker image, so I'm biased

+4
source

Source: https://habr.com/ru/post/976582/


All Articles