How to install MongoDB on Mac

How to install MongoDB on Mac

Table of contents

No heading

No headings in the article.

  1. Open the Terminal app on your Mac.

  2. Install Homebrew by running the following command:

    
     /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  3. Check the zshrc file, hit 'cd' so that you will be in current directory then hit 'ls -la' which gives long listing and all the files which are hidden.Check whether .zshrc file is listed there or not.If not then hit 'vim .zshrc' and press i to get into insert mode and type ':wq' and hit enter, but maker sure after this you restart your mac or you can run this command source ~/.zshrc , so that it will make .zshrc file for you.

  4. Once Homebrew is installed, update the Homebrew package list by running the following command:

brew update
  1. Install xcode by running the following command-
xcode-select --install
  1. Tap into the mongodb
brew tab mongodb/brew
  1. Install mongoDB by running the following command:
brew install mongodb-community@6.0
  1. Start the services of mongodb server
brew services start mongodb-community@6.0
  1. Stop the services of mongodb server
brew services stop mongodb-community@6.0
  1. To run MongoDB (i.e. the mongod process) manually as a background process, run:

    --> For macOS running on Intel processors:

     mongod --config /usr/local/etc/mongod.conf --fork
    

    --> For macOS running on Apple Silicon Processors-

     mongod --config /opt/homebrew/etc/mongod.conf --fork
    
    1. Install mongoshell
    mongosh
  1. Now you can run all the mongodb commands,for example:
    show dbs

That's it! With these steps, you should have successfully install mongodb on mac.