ZL
About Articles Contact
Published on Feb 14, 2020
Filed under:
#mongodb

Installing MongoDB on Mac (Catalina and non-Catalina)

I had to reconfigure my Macbook after sending it for repairs. During the reconfiguration period, I noticed the instructions I linked to in “Setting up a local MongoDB connection” were outdated.

Here’s an updated version on how to install MongoDB on a Mac.

There are a few steps:

First, you install Homebrew. If you’re curious about what Homebrew is, read this article.

Terminal window
# Installs Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Second, find the MongoDB tap.

Terminal window
brew tap mongodb/brew

Third, install MongoDB.

brew install mongodb-community

MongoDB is now installed on your computer.

Preparations (Before MacOS Catalina)

Before you can use MongoDB, you need to create a /data/db folder on your computer to use MongoDB. You can create this folder with the following command:

sudo mkdir -p /data/db

You also need to give permissions to use it:

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

Now you can follow the rest of the article to set up your MongoDB connection.

Preparations (MacOS Catalina onwards)

Apple created a new Volume in Catalina for security purposes. If you’re on Catalina, you need to create the /data/db folder in System/Volumes/Data.

Use this command:

sudo mkdir -p /System/Volumes/Data/data/db

Then, use this command to give permissions:

sudo chown -R `id -un` /System/Volumes/Data/data/db

Using MongoDB

In the past, I can run the mongod command to start MongoDB. This no longer works out for the box from MongoDB v4.2.3 onwards.

The best way to start MongoDB now is via brew services.

Starting MongoDB

Use this command:

Terminal window
brew services run mongodb-community

MongoDB will start as a background service. Here’s what you’ll see:

Started MongoDB with brew services
Note

You can use start instead of run. start will start MongoDB automatically when you login into your Macbook. I prefer run since I don’t want MongoDB to be running all the time.

Checking if MongoDB is running

Use this command:

Terminal window
brew services list

Homebrew will list all running services. If MongoDB is running, mongodb-community will have a status set to started.

Mongodb-community has status set to started.

The Mongo Shell

If MongoDB is running, you should be able to access the Mongo shell with the mongo command.

Terminal window
mongo
Starts the Mongo shell.

Stopping MongoDB

Use this command:

Terminal window
brew services stop mongodb-community

Homebrew will stop MongoDB and let you know.

Stopped MongoDB

Aliases to make these easier

It’s a chore typing brew services run mongodb-community every time I want to start MongoDB.

I created some aliases to make things easier for me. Here are my aliases:

Terminal window
alias mongod='brew services run mongodb-community'
alias mongod-status='brew services list'
alias mongod-stop='brew services stop mongodb-community'

What’s next?

If you haven’t already, you should learn how to set up a local MongoDB connection.

Previous Preventing a Windows PC from adjusting the screen's brightness automatically Next Syncing Visual Studio Code settings between Mac and Windows

Join My Newsletter

I share what I’m learning on this newsletter: code, building businesses, and living well.

Sometimes I write about technical deep-dives, product updates, musings on how to live, and sometimes my struggles and how I’m breaking through.

Regardless of the type of content, I do my best to send you an update every week.

If you’re into making things and growing as a person, you’ll probably feel at home here.

“

Zell is the rare sort of developer who both knows his stuff and can explain even the most technical jargon in approachable — and even fun — ways!

I’ve taken his courses and always look forward to his writing because I know I’ll walk away with something that makes me a better front-ender.

Geoff Graham
Geoff Graham — Chief Editor @ CSS Tricks
The Footer

General

Home About Contact Testimonials Tools I Use

Projects

Magical Dev School Splendid Labz

Socials

Youtube Instagram Tiktok Github Bluesky X

Follow Along

Email RSS
© 2013 - 2025 Zell Liew / All rights reserved / Terms