Installing MongoDB on macOS Catalina/Big Sur(or Older)

Shashank Verma
2 min readMar 7, 2021

--

I had to reconfigure my Macbook after sending it in for repair. During the setup, I noticed that my instructions for Local MongoDB Setup were outdated and didn’t work any longer for macOS Big Sur.

As you all know Mongo puts its database in /data/db and Apple revoked access to the root folder, presenting you with a ‘read-only access’ warning. I went through tons of forums and did the tiresome work for you.

Here are the steps:

Install Homebrew

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

Find MongoDB tap.

brew tap mongodb/brew

Install MongoDB.

brew install mongodb-community

MongoDB is now installed on your Mac.

Before you can use MongoDB, you need to create a /data/db folder but Apple created a new volume on macOS Catalina for security purposes. So, we will create the folder in System/Volumes/Data .

Use this command:

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

Then, give permissions to the folder:

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

Starting MongoDB

The ‘mongod’ command to start MongoDB no longer works out of the box for me. The best way to start MongoDB is now via ‘brew services’ .

brew services run mongodb-community
MongoDB will start as a background service

Note: You can use start instead of run. start will start MongoDB automatically when you log into your Mac. I prefer run as I don’t want it to be running all the time.

Mongo Shell

If MongoDB is running, you should be able to access the Mongo shell

Use this command:

mongo

Stopping MongoDB

brew services stop mongodb-community

--

--

Responses (2)