I installed MongoDB a lot of times on my macbook. And every time I keep forgetting how.
So I was thinking… Let’s create a little page on how… so I can find it easily.
I hope you can also use this small manual.
Update Homebrew’s package database.
In a system shell, issue the following command:
You can install MongoDB via brew with several different options. Use one of
the following operations:
Install the MongoDB Binaries on Mac OS
To install the MongoDB binaries, issue the following command in a system
brew install mongodb
Create the MongoDB data directory
Before you start MongoDB for the first time, create the directory to which the
mongod process will write data.
By default, the mongod process uses the /data/db directory. If you create a
directory other than this one, you must specify that directory in the dbpath
option when starting the mongod process later in this procedure.
The following example command creates the default /data/db directory:
sudo mkdir -p /data/db
Set permissions for the data directory
Before running mongod for the first time, ensure that the user account running
mongod has read and write permissions for the directory.
sudo chmod 0755 /data/db && sudo chown $USER /data/db
Run MongoDB on MacOS.
To run MongoDB, run the mongod process at the system prompt. If necessary,
specify the path of the mongod or the data directory.
To run MongoDB Simply enter mongod at the system prompt:
Stop MongoDB on MacOS
Later, to stop MongoDB, press Control+C in the terminal where the mongod
instance is running.
brew services start mongodbbrew services restart mongodbbrew services stop mongodb
Extra MongoDB tools for Mac OS
There is a Toolset for the MongoDB Database which are a suite of command-line utilities for working with MongoDB. Installingthe Database Tools on the macOS platform is very simple.
Just run the following line in your terminal
brew install mongodb-database-tools
Once installed, you can run any of the Database Tools directly from your macOS Terminal.