Download & Install MongoDB on Mac
MongoDB is a popular document-oriented NoSQL database system. It provides a flexible and scalable approach for storing and retrieving data. It organizes data into flexible JSON-like documents and supports dynamic schemas, allowing for easy data modeling and agile development. With its robust features like high availability, horizontal scalability, and built-in sharing, MongoDB is widely used for modern web and mobile applications. And here you will download MongoDB on Mac.
Requirement for MongoDB
MongoDB 4.0 may lose data during unclean shutdowns on macOS 10.12.x, 10.13.x, and 10.14.0. This issue was fixed by Apple in macOS 10.14.1. You are recommended to use macOS 10.13 or later.
x86_64
MongoDB requires the following minimum x86_64 microarchitectures:
For Intel x86_64, MongoDB requires one of:
Sandy Bridge or later Core processor, Tiger Lake or later Celeron or Pentium processor.
For AMD x86_64, MongoDB requires:
Bulldozer or later processor.
Starting in MongoDB 5.0, mongod, mongos, and the legacy mongo shell no longer support x86_64 platforms which do not meet this minimum microarchitecture requirement.
MongoDB only supports Oracle Linux running the Red Hat Compatible Kernel (RHCK). MongoDB does not support the Unbreakable Enterprise Kernel (UEK).
How to install MongoDB on macOS?
Install Xcode Command-Line Tools
Homebrew requires the Xcode command-line tools from Apple’s Xcode. To install the Xcode command-line tools, you will use this command on macOS Terminal:
xcode-select –install
After the installation of Command-line, you will need to install Homebrew on your Mac.
Install Homebrew
To install Homebrew on your macOS, follow these steps:
1. Open a terminal on your macOS system.
2. Paste the following command and press Enter:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
3. The installation script will start downloading Homebrew and prompt you for your macOS user password. Enter your password when requested and press Enter.
Wait for the installation process to complete. It may take a few minutes. Once the installation is finished, you can verify if Homebrew is installed correctly by typing `brew` in the terminal and pressing Enter. You should see the Homebrew logo and a list of available commands.
You have now successfully installed Homebrew on your macOS system. Now we will download MongoDB on Mac and then do the installation. Homebrew is important for downloading MongoDB on Mac, as we are going to use it.
Installing MongoDB Community Edition
To download and install MongoDB Community Edition on macOS using Homebrew, we will follow these steps:
1. Open a terminal on your macOS system.
2. Update Homebrew by running the following command:
brew update
`brew update` updates the Homebrew package manager by fetching the latest package information from the remote repository. Now we will install it.
3. Install MongoDB Community Edition by running the following command:
brew install mongodb-community
4. After the installation is complete, create the default data directory for MongoDB by running the following command:
sudo mkdir -p /data/db
- The command `sudo mkdir -p /data/db` creates a directory named “db” within the “/data” directory path.
- sudo: It is a command that allows you to run a command with administrative privileges. It prompts for your password before executing the command.
- mkdir: It is a command used to create directories (folders) on the file system.
- -p: It is an option that tells the `mkdir` command to create intermediate directories if they don’t already exist. In this case, it ensures that both the “/data” directory and the “db” directory are created if they are not already present.
- /data/db: It specifies the path to the directory that you want to create. In this case, it is creating the “db” directory within the “/data” directory.
- This command is commonly used when setting up MongoDB because the default data directory for MongoDB is “/data/db”. By creating this directory, you provide a location for MongoDB to store its data files.
5. Set the appropriate permissions for the data directory by running the following command:
sudo chown -R `id -un` /data/db
That’s it! MongoDB Community Edition is now installed on your macOS system using Homebrew. You can start the MongoDB server by running the `mongod` command in the terminal.