Skip to main content

Installing MongoDB

Below is your requested beginner-friendly tutorial on installing MongoDB.


Preparing for Installation

Before you install MongoDB, make sure your system meets the requirements:

  • MongoDB requires a 64-bit CPU. It cannot run on a 32-bit CPU.

  • MongoDB requires at least 2GB of RAM.

  • MongoDB supports Linux, Windows, and macOS. Make sure your OS is up to date.

  • Ensure you have administrative privileges on your system.

Downloading MongoDB

  1. Visit the MongoDB official download page at https://www.mongodb.com/try/download/community.

  2. Select the correct version for your operating system.

  3. Choose the package type. For Windows, choose MSI. For macOS, choose TGZ. For Linux, there should be specific packages for various distributions.

  4. Click Download.

Installing MongoDB

Windows

  1. Open the downloaded MSI file to start the installation.

  2. Follow the installation wizard’s prompts. Accept the license agreement.

  3. Choose Complete installation type for a full installation, which includes MongoDB, MongoDB Compass (a GUI for MongoDB), and the MongoDB tools.

  4. Choose the Run service as Network Service user option.

  5. Choose Install MongoDB Compass if you want a graphical interface.

  6. Click Install.

macOS

  1. Open the downloaded TGZ file. This will extract the files into a new directory.

  2. Move the extracted files to your preferred location. A common location is /usr/local/mongodb.

  3. Add the MongoDB bin directory to your PATH. You can do this by editing your ~/.bash_profile file (or ~/.zshrc if you're using Zsh) and adding the following line:

export PATH=/usr/local/mongodb/bin:$PATH
  1. Save the file, then run source ~/.bash_profile (or source ~/.zshrc for Zsh) to reload your shell.

Linux

The installation process differs by distribution. Refer to the official MongoDB documentation for your specific distribution.

Starting MongoDB

Windows

MongoDB is installed as a Windows Service and will start up with your machine by default.

macOS and Linux

You can start MongoDB by running the mongod command in your terminal. If you want MongoDB to start with your system, you have to configure it as a system service.

Verifying the Installation

In your terminal, run the command mongo. This will open the MongoDB shell if your installation was successful.


Congratulations! You've now installed MongoDB on your system. In the next steps of your MongoDB journey, you'll learn how to create databases, insert data and query your data. Enjoy exploring MongoDB!