← Back to MongoDB Course | Chapter 1: Introduction | Lesson 5 of 7

Installing MongoDB

You can install MongoDB Community Edition locally or run it in a Docker container.

In this page:

  1. Installing MongoDB

Installing MongoDB

On Linux use your package manager after adding the MongoDB repository, on macOS use Homebrew, and on Windows use the MSI installer. Docker is the quickest way: run the official mongo image and connect to port 27017.

Install mongosh separately if it is not included.

Note: Docker lets you try MongoDB without installing anything on your machine.

Example: Installing MongoDB

bash
# macOS
$ brew tap mongodb/brew && brew install mongodb-community
$ brew services start mongodb-community

# Docker (any OS)
$ docker run -d --name mongo -p 27017:27017 mongo:7
$ docker exec -it mongo mongosh
Current Mongosh Log ID: 65a1b2c3d4e5f60718293a4b
test>

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
Common Mistakes
  1. Forgetting to start the mongod service
  2. Exposing port 27017 to the internet without authentication
  3. Not installing mongosh
Chapter Summary
  • Install Community Edition or use Docker
  • mongod is the server, mongosh is the shell
  • Default port is 27017
  • Enable authentication before exposing it
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.