Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct way to start a mongod service on linux / OS X?

I've installed mongodb and have been able to run it, work with it, do simple DB read / write type stuff. Now I'm trying to set up my Mac to run mongod as a service.

I get "Command not found" in response to:

 init mongod start 

In response to:

~: service mongod start service: This command still works, but it is deprecated. Please use launchctl(8) instead. service: failed to start the 'mongod' service 

And if I try:

~: launchctl start mongod launchctl start error: No such process 

So obviously I'm blundering around a bit. Next step seems to be typing in random characters until something works. The command which does work is: mongod --quiet & I'm not sure, maybe that is the way you're supposed to do it? Maybe I should just take off 'quiet mode' and add > /logs/mongo.log to the end of the command line?

I'm building a development environment on a Mac with the intention of doing the same thing on a linux server. I'm just not sure of the Bash commands. All the other searches I do with trying to pull up the answer give me advice for windows machines.

Perhaps someone knows the linux version of the commands?

Thanks very much

like image 475
Alex C Avatar asked Apr 08 '11 14:04

Alex C


People also ask

How do I start the MongoDB service on a Mac?

Start the MongoDB service on macOSIn the terminal window, start the service by typing mongod . When you want to stop the MongoDB server, it's the same as Homebrew. Press CTRL+C.


1 Answers

Edit: you should now use brew services start mongodb, as in Gergo's answer...

When you install/upgrade mongodb, brew will tell you what to do:

To have launchd start mongodb at login:

    ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents 

Then to load mongodb now:

    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist 

Or, if you don't want/need launchctl, you can just run:

    mongod 

It works perfectly.

like image 199
Mario Alemi Avatar answered Sep 19 '22 15:09

Mario Alemi