How to install MongoDB on Mac Air M1
1. Follow this official installation guide: https://www.mongodb.com/docs/v4.4/tutorial/install-mongodb-on-os-x/
2. After installing, write mongo -version to see if it's working or not. If it's not working, then follow step 3.
3. Steps:
- Open Terminal and navigate to your user directory.
- Run touch ~/.bash_profile and then open ~/.bash_profile.
- In TextEdit, add export PATH="<mongo-directory>/bin:$PATH" (Keep the quote marks - related to white spaces). To get PATH check below section.
- Save the .bash_profile file and Quit (Command + Q) Text Edit.
- Run source ~/.bash_profile.
- Run echo $PATH and check if you see that the Mongo binary was added.
NOTE: Notice that the PATH variable is now available only for the current terminal and not to processes that were already started in the session. In order to make it available outside the current terminal - you'll have to log out and log in.
Get MongoDB PATH
- Open up your Terminal
- Type brew list to check the formulae of the installed mongodb
- In my case, it is mongodb-community@4.4.
- In the terminal, type brew list mongodb-community@4.4 to get the directory of the mongodb installed in your machine.
- Copy the bin path of your mongodb: /opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/bin
- Open up your .zshrc file with any text-editor
- Add this line to the file: export PATH="/opt/homebrew/Cellar/mongodb-community@4.4/4.4.13/bin:${PATH}"
- Try mongo --version in your terminal, if you see similar output like shown below, you are good to go.