Nearby lessons
2 of 22💻 Installing MongoDB
MongoDB can be installed on different operating systems including Windows, macOS, and Linux. Below are the steps to install MongoDB and MongoDB Compass (GUI) on these platforms.
🪟 Windows Installation
- Go to the MongoDB Community Server download page.
- Download the MSI installer for Windows.
- Run the installer and follow the setup wizard.
- Select “Complete” setup type.
- Choose to install MongoDB as a Service (recommended).
- Install MongoDB Compass (GUI) when prompted or download it separately from MongoDB Compass.
- Verify installation: Open Command Prompt and run
mongo --version.
🍏 macOS Installation
- Install Homebrew if not already installed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - Update Homebrew:
brew update - Install MongoDB Community Edition:
brew tap mongodb/brewthenbrew install mongodb-community@6.0 - Start MongoDB service:
brew services start mongodb-community@6.0 - Install MongoDB Compass (GUI) from MongoDB Compass.
- Verify installation:
mongo --version
🐧 Linux Installation (Ubuntu/Debian)
- Import the public key:
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add - - Create the list file for MongoDB:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list - Update packages:
sudo apt-get update - Install MongoDB:
sudo apt-get install -y mongodb-org - Start MongoDB:
sudo systemctl start mongod - Enable MongoDB to start on boot:
sudo systemctl enable mongod - Install MongoDB Compass (GUI) from MongoDB Compass (Debian/Ubuntu package).
- Verify installation:
mongo --version
⚡ Starting MongoDB Shell and Compass
After installing MongoDB, you can start the MongoDB shell and MongoDB Compass to interact with your databases:
- Open Command Prompt / Terminal.
- Type
mongoshto open the MongoDB shell. - Open MongoDB Compass to connect to your local MongoDB instance using
mongodb://localhost:27017. - Start creating databases, collections, and documents either via the shell or Compass GUI.
💡 Notes
- MongoDB Community Edition is free and open-source.
- MongoDB Compass provides a GUI interface for easier database management.
- Always verify your MongoDB installation using
mongo --versionormongosh --version. - MongoDB Compass allows visual CRUD operations and data exploration without using the shell.