To install MongoDB, you can follow the steps outlined below. The installation process might vary slightly depending on your operating system. Here, I'll cover installations for popular operating systems: Windows, macOS, and Linux.
Windows:
-
Download MongoDB Installer:
- Visit the official MongoDB website: MongoDB Download Center.
- Choose the "Community Server" tab and select the appropriate version for Windows.
- Download the installer (MSI).
-
Run the Installer:
- Run the downloaded MSI installer.
- Follow the installation wizard, accepting the default options. You can customize the installation directory if needed.
-
Complete the Installation:
- The installer will prompt you to install MongoDB Compass, a graphical user interface for MongoDB. You can choose to install it or skip it.
- Complete the installation process.
-
Verify Installation:
- Open a Command Prompt and run the following command to start the MongoDB server:
mongod
- Open another Command Prompt and run the following command to open the MongoDB shell:
mongo
- Open a Command Prompt and run the following command to start the MongoDB server:
macOS:
-
Install Homebrew (if not installed):
- Open Terminal.
- Install Homebrew using the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
Install MongoDB:
- Run the following command to install MongoDB using Homebrew:
brew tap mongodb/brew brew install mongodb-community
- Run the following command to install MongoDB using Homebrew:
-
Start MongoDB:
- Run the following command to start MongoDB:
brew services start mongodb-community
- Run the following command to start MongoDB:
-
Verify Installation:
- Open a new Terminal window and run the MongoDB shell:
mongo
- Open a new Terminal window and run the MongoDB shell:
Linux (Ubuntu/Debian):
-
Import MongoDB GPG Key:
- Open a terminal and import the MongoDB GPG key:
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
- Open a terminal and import the MongoDB GPG key:
-
Add MongoDB Repository:
- Add the MongoDB repository to the sources list:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
- Add the MongoDB repository to the sources list:
-
Install MongoDB:
- Update the package list and install MongoDB:
sudo apt-get update sudo apt-get install -y mongodb-org
- Update the package list and install MongoDB:
-
Start MongoDB:
- Start the MongoDB service:
sudo systemctl start mongod
- Start the MongoDB service:
-
Enable MongoDB to Start on Boot:
- Enable MongoDB to start on system boot:
sudo systemctl enable mongod
- Enable MongoDB to start on system boot:
-
Verify Installation:
- Open a terminal and run the MongoDB shell:
mongo
- Open a terminal and run the MongoDB shell:
Comments