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:

systemLog:
  destination: file
  path: /usr/local/var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /usr/local/var/mongodb
net:
  bindIp: 127.0.0.1

Hope this helps!


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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