You can install MongoDB using two different methods one is using .tgz tarball and another is using Homebrew. Here, we will discuss how to install MongoDB using .tgz tarball. Follow each step carefully :
- Go to mongodb-community and select the version 5.0.11. Make sure you choose macOS as the platform and 'tgz' as the file format and click the download button.
- Once the tgz file is downloaded, go to the macOS terminal (open Finder and go to Applications/Utility folder) to extract it. Most likely, your MongoDB will get downloaded in the Downloads folder. For this, type the following command in the terminal (change file name after tar command according to the file you downloaded):
cd Downloads/
ls
tar xzf mongodb-macos-x86_64-5.0.11.tgz
- Now, let us move MongoDB folder to your home folder. This will ask for your system password. Provide the password.
sudo mv mongodb-macos-x86_64-5.0.11 ~/mongodb
-
Next, you have to create the db folder. By default, MongoDB writes or stores the data in the folder called /data/db, but newer MacOS disallowed it. So let use set it data/db inside your home folder. The command for this will be
sudo mkdir -p ~/data/db
sudo chown $USER ~/data/db
Note: For changing the permission, you need to know your username first. To know your username, type the command: whoami