2. Installing and Setting Up MongoDB 🧰
To get started with MongoDB, the first step is installing it on your system. Depending on your operating system, installation steps vary.
Installing on Windows:
- Download the latest MongoDB MSI installer from the official website.
- Run the installer with default settings.
- Optionally, install MongoDB Compass for visual data management.
Installing on macOS:
- Use Homebrew:
brew tap mongodb/brew
brew install mongodb-community
- Start MongoDB with:
brew services start mongodb-community
Installing on Linux:
- Use your distro's package manager, e.g., for Ubuntu:
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
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
sudo apt-get update
sudo apt-get install -y mongodb-org
Starting the MongoDB Service:
mongod --dbpath /your/data/directory
Once installed, verify by connecting:
mongo