MongoDB provides different installation methods for various operating systems, so be sure to choose the one that matches your system.
Step 1: Choose the Installation Method
MongoDB offers various installation methods, including Community Server, Atlas (MongoDB's hosted database service), and Docker. Here, I'll cover the installation of the MongoDB Community Server, which is the open-source version of MongoDB that you can install on your local machine.
Step 2: Download MongoDB (Community Server)
Visit the MongoDB download page: MongoDB Download Center
Choose your operating system (Windows, macOS, or Linux) and the package type (ZIP, MSI, or RPM).
For example, if you're using Windows, you can select "Windows" and download the MSI package.
Download the package to your local machine.
Step 3: Install MongoDB
The installation steps vary depending on your operating system. Here are instructions for Windows, macOS, and Linux:
Run the downloaded MSI installer.
Follow the installation wizard.
You can choose to install MongoDB as a service or use the default settings.
Open the downloaded DMG file.
Drag and drop the MongoDB icon into the Applications folder.
Linux (using APT package manager, for example):
Open a terminal.
Import the MongoDB GPG key:
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.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/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
Update the package repository:
sudo apt-get update
sudo apt-get install -y mongodb-org
The following packages have unmet dependencies: mongodb-org-mongos : Depends: libssl1.1 (>= 1.1.1) but it is not installable mongodb-org-server : Depends: libssl1.1 (>= 1.1.1) but it is not installable mongodb-org-shell : Depends: libssl1.1 (>= 1.1.1) but it is not installable E: Unable to correct problems, you have held broken packages.
In case you get the error message above in Ubuntu, refer to this solution on StackOverflow https://stackoverflow.com/questions/73656873/unable-to-install-mongodb-in-ubuntu-22-04-mongodb-org-libssl1-1
Step 4: Start MongoDB
Windows: If you installed MongoDB as a service, it should automatically start with your system. Otherwise, you can start MongoDB by running the
macOS and Linux: Open a terminal and start the MongoDB server with the following command:
sudo service mongod start
Step 5: Verify MongoDB is Running
You can verify that MongoDB is running correctly by opening a terminal and running the following command:
This will open the MongoDB shell, and you should see a prompt indicating a successful connection to the MongoDB server.
You have successfully installed and started MongoDB on your system. You can now start using MongoDB for your projects, and you can also interact with it through MongoDB drivers and tools like
mongo Shell and MongoDB Compass.