MongoDB โ MongoDB Installation & Setup
Complete guide to downloading, installing, and configuring MongoDB Community Server 7.0+ on Windows, macOS, and Linux. Learn how to verify the mongod background service and launch mongosh.
1MongoDB Architecture: Server vs Shell vs GUI
Before installing, it is essential to understand the three distinct binaries in the MongoDB ecosystem:
mongod(Database Daemon): The background database server process that handles disk read/write, memory caching, index creation, and client connections.mongosh(MongoDB Shell): The modern interactive JavaScript command-line interface used to run queries and admin commands.- MongoDB Compass: The official graphical user interface (GUI) for visual data inspection.
2Installing MongoDB on Windows (Step-by-Step)
- Go to the official MongoDB Download Center and download the Windows MSI Installer for MongoDB Community Server 7.0+.
- Run the installer executable. Choose Complete Setup.
- Check the option "Install MongoDB as a Service". This ensures
mongodstarts automatically when Windows boots up. - Leave the default Service Name (
MongoDB) and Data Directory paths (C:\Program Files\MongoDB\Server\7.0\data\). - Check "Install MongoDB Compass" to get the official visual GUI client. Click Install!
Windows Command Prompt / PowerShell Verification
# Check if mongod service is running
net start | findstr MongoDB
# If not running, start it manually
net start MongoDB
3Installing MongoDB on macOS via Homebrew
For Mac users, Homebrew is the easiest way to install and manage MongoDB:
macOS Terminal Commands
# 1. Tap the official MongoDB Homebrew repository
brew tap mongodb/brew
# 2. Install MongoDB Community Edition
brew install mongodb-community@7.0
# 3. Start MongoDB background service
brew services start mongodb-community@7.0
# 4. Verify service status
brew services list
4Installing MongoDB on Linux (Ubuntu/Debian)
Ubuntu Terminal Commands
# 1. Import official GPG key
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-server-7.0.gpg
# 2. Add APT repository list
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
# 3. Update package list and install
sudo apt update
sudo apt install -y mongodb-org
# 4. Start & enable systemd service
sudo systemctl start mongod
sudo systemctl enable mongod
5Verifying Installation with mongosh
Open your terminal or command prompt and execute mongosh:
mongosh Output
$ mongosh
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000
Using MongoDB: 7.0.5
Using Mongosh: 2.1.1
test> db.runCommand({ ping: 1 })
{ ok: 1 }
If you see { ok: 1 }, congratulations! Your local MongoDB database engine is running smoothly.