Mongodb – Dont want to have to start mongod with `sudo mongod`

macosmongodb

I just downloaded mongodb onto my brandy new MacBookAir with OS X 10.9.5 by doing brew install mongodb.

I tried to run mongod from Terminal and it said "no /data/db" so I created it with sudo mkdir /data and sudo mkdir /data/db.

Running mongod now I get "Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied" but I can run it perfectly fine with sudo mongod.

How can I make it so that I don't have to run mongod with sudo, but instead just as simply mongod?

(I had it like that on my last computer but do not remember what I did at all, and that computer was all messed up anyway.)

Best Answer

This worked for me:

sudo chmod -R 777 /data/db

then

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

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

(PS I'm sorry I know this is a very old question but I found it while trying to look for an answer to my problem; and since I managed to solve it I thought I'd put this here for anyone in the future. Also I'm not sure which of those two commands made the difference, but it worked.)

Related Topic