'sudo mongod' works, 'mongod' doesn't - The Solution

I am currently learning how to use MongoDB and Node JS together and I was following along a tutorial but when it came to the point to start the MongoDB server, it kept failing by running mongod on the command line. The error I got was:

$ mongod
2015-07-04T09:06:37.068-0400 I STORAGE  [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating  
2015-07-04T09:06:37.069-0400 I CONTROL  [initandlisten] dbexit:  rc: 100  

When I ran sudo mongod , the MongoDB server started normally. I did some Googling and found this StackOverflow answer. The answer solved my issue. It was a permission issue and I had to run this command to make it work:

sudo chown -R USERNAME_HERE /data  

In the StackOverflow answer it said to do it either on /data/db or /data. When I tried it on /data/db it still didn't work. I had to do it on /data.

Show Comments