Installing MongoDB
Step-by-step guide to installing MongoDB on different platforms
Installing MongoDB is straightforward, and the process varies slightly depending on your operating system. Below are the steps for installing MongoDB on Windows, macOS, and Linux.
Installing MongoDB on Windows
- Download the MongoDB installer from the official MongoDB website.
- Run the installer and follow the installation prompts.
- Choose the complete installation option.
- After installation, set up MongoDB as a Windows service or run it manually from the command prompt.
Installing MongoDB on macOS
- Open a terminal window.
- Install Homebrew if you don't have it:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Use Homebrew to install MongoDB:
brew tap mongodb/brew
followed bybrew install mongodb-community@4.4
- Start MongoDB:
brew services start mongodb/brew/mongodb-community
Installing MongoDB on Linux
- Open a terminal window.
- Import the public key used by the package management system:
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
- Create a list file for MongoDB:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
- Reload the local package database:
sudo apt-get update
- Install the MongoDB packages:
sudo apt-get install -y mongodb-org
- Start MongoDB:
sudo systemctl start mongod
Example: Starting MongoDB on Windows
Once MongoDB is installed on Windows, you can start it from the command prompt.
Command Prompt Commands
cd C:\Program Files\MongoDB\Server\4.4\bin mongod