Install and run mongodb on macOS as a non-root user

Photo by Jess Bailey (Unsplash)

Installing and running mongodb on a mac is very easy with homebrew:

brew tap mongodb/brew
brew install mongodb-community
brew services start mongodb-community

It runs on localhost as a non-root user. You can verify that mongodb is running by searching for mongod in your running processes and by checking for the logs:

ps aux | grep -v grep | grep mongod
tail /usr/local/var/log/mongodb/mongo.log

Use mongo command to start a mongo shell to the running instance. CTRL-D to exit the mongo shell.

The default data directory is /usr/local/var/mongodb. It is created when mongodb is installed with homebrew. The path is set in dbPath in /usr/local/etc/mongod.conf. See the default configuration on my mac:

  destination: file
  path: /usr/local/var/log/mongodb/mongo.log
  logAppend: true
  dbPath: /usr/local/var/mongodb

Hope this helps!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s