Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Installing MongoDB

Step-by-step guide to installing MongoDB on different platforms

Installing MongoDB is straightforward, and the process varies slightly depending on your operating system. Below are the steps for installing MongoDB on Windows, macOS, and Linux.

Installing MongoDB on Windows

  1. Download the MongoDB installer from the official MongoDB website.
  2. Run the installer and follow the installation prompts.
  3. Choose the complete installation option.
  4. After installation, set up MongoDB as a Windows service or run it manually from the command prompt.

Installing MongoDB on macOS

  1. Open a terminal window.
  2. Install Homebrew if you don't have it: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  3. Use Homebrew to install MongoDB: brew tap mongodb/brew followed by brew install mongodb-community@4.4
  4. Start MongoDB: brew services start mongodb/brew/mongodb-community

Installing MongoDB on Linux

  1. Open a terminal window.
  2. Import the public key used by the package management system: wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
  3. Create a list file for MongoDB: echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
  4. Reload the local package database: sudo apt-get update
  5. Install the MongoDB packages: sudo apt-get install -y mongodb-org
  6. Start MongoDB: sudo systemctl start mongod

Example: Starting MongoDB on Windows

Once MongoDB is installed on Windows, you can start it from the command prompt.

Command Prompt Commands

cd C:\Program Files\MongoDB\Server\4.4\bin
mongod