MongoDB Installation

Beginner
14 min read
Updated: Oct 2026
Setup guide
Windows · macOS · Linux

What Is MongoDB Installation?

Installing MongoDB means setting up the MongoDB server so applications can store and retrieve data from a MongoDB database.

Components
             MongoDB
                |
        +-------+-------+
        |       |       |
        v       v       v
      mongod  mongosh Compass
      Server    Shell    GUI (optional)

mongod is the server process. mongosh is the shell that connects to it. Compass is an optional GUI. Atlas is MongoDB’s managed cloud database—no local mongod required when you use Atlas alone.

MongoDB Installation Options

Pick the path that matches how you want to run MongoDB.

OptionDescription
Local installationRun MongoDB Server (mongod) on your computer or server
MongoDB AtlasUse MongoDB as a managed cloud service (no local server required)
DockerRun MongoDB in a container (official Docker docs)
MongoDB CompassGUI client for working with MongoDB—not the server itself

Compass does not install MongoDB Server. Atlas does not require a local mongod when you use the cloud deployment.

What Gets Installed?

Not every method installs every tool. Know the roles:

Roles
mongod   → MongoDB Server (stores + processes data)
mongosh  → Shell client (connect + run commands)
Compass  → Optional GUI client
Tools    → Optional utilities (import/export, etc.)
  • MongoDB Server (mongod) — accepts connections and manages data.
  • MongoDB Shell (mongosh) — interactive CLI for developers and admins.
  • MongoDB Compass — optional graphical interface.
  • Database Tools — optional utilities; some install methods include them.

On Windows MSI installs, mongosh is installed separately from the server. On macOS Homebrew Community installs, mongosh is typically included with the formula. Always confirm against the current official docs for your method.

How MongoDB Works After Installation

Apps
Your Application
       |
       v
 MongoDB Driver
       |
       v
     mongod
       |
       v
 MongoDB Database
Interactive
mongosh
   |
   v
mongod
   |
   v
Database

Applications normally connect through a MongoDB driver. Developers use mongosh for interactive learning and admin tasks.

System Requirements

Requirements depend on operating system, MongoDB version, CPU architecture, and install method. MongoDB documents supported platforms per release—check the official installation page for your version before you install.

Examples from current Community docs (verify for your release): Windows Server 2022 and Windows 11 (x86_64); macOS 14+ on supported CPUs; specific Ubuntu LTS and RHEL/Rocky/AlmaLinux versions. MongoDB is not supported on Windows Subsystem for Linux (WSL).

Install by Operating System

Choose your platform. Windows is shown first—switch tabs for macOS or Linux. Commands are OS-specific; do not mix them.

Windows Installation

Current Community installs commonly use the MSI wizard. Download from the MongoDB Community Edition download page or the Community releases page. Follow the official Windows installation tutorial for your MongoDB version. Detailed steps can also live on a dedicated Windows installation page later.

Flow
Download MongoDB MSI
      ↓
Install MongoDB Server
      ↓
Install mongosh separately
      ↓
Start MongoDB (service or manual)
      ↓
Connect with mongosh

Service vs manual: a service is managed by Windows; manual means you start mongod yourself. If installed as a service, it typically starts after a successful install.

mongosh
mongosh

A successful shell connection means a MongoDB deployment is reachable on the host/port you used (default local URI: mongodb://localhost:27017).

Starting MongoDB

Idea
Service-based
    |
    v
OS manages mongod


Manual
    |
    v
You start mongod directly
OSTypical start
Windows (service)Services console → MongoDB → Start
macOS (Homebrew)brew services start mongodb-community@<version>
Linux (systemd)sudo systemctl start mongod

Do not mix Windows, macOS, and Linux commands in one script. Installing MongoDB is different from starting it—the server must be running before clients connect.

Verify MongoDB Is Running

The simplest check: open the shell and ping the server.

mongosh
mongosh

db.runCommand({ ping: 1 })
Expected
{ ok: 1 }

How It Works

  1. mongosh attempts to connect to MongoDB (default local host/port).
  2. db.runCommand({ ping: 1 }) sends a ping command to the server.
  3. A response with ok: 1 means the connection is working.

First MongoDB Commands

After connect, try a tiny write/read cycle.

mongosh
db
show dbs

db.test.insertOne({
  message: "MongoDB is working"
})

db.test.find()

How It Works

  1. db shows the current database context.
  2. show dbs lists databases visible to you.
  3. insertOne() creates a document in the test collection.
  4. find() reads the documents back—full write/read cycle complete.

MongoDB Installation Walkthrough

Path
Install MongoDB
      ↓
Start MongoDB
      ↓
Open mongosh
      ↓
Run ping
      ↓
Create a document
      ↓
Read the document

Use the Install by Operating System tabs (Windows, macOS, or Linux), then run the verify and first-command steps above. Do not combine incompatible OS commands.

MongoDB Compass

MongoDB Compass is a graphical user interface for MongoDB. It is optional.

Idea
MongoDB Server (mongod / Atlas)
              ↑
              |
           Compass

MongoDB Server ≠ Compass

Use Compass to browse databases and collections, view or edit documents, and explore features your deployment allows. Installing Compass does not install the server. Download it from the official Compass download page. Learn more on a dedicated Compass page when available.

MongoDB Atlas

MongoDB Atlas is MongoDB’s managed cloud database service. See the official Atlas documentation or create an Atlas account.

Compare
Local MongoDB

Your Computer
     |
     v
   mongod
     |
     v
Database


MongoDB Atlas

Your Application
     |
     v
Internet
     |
     v
MongoDB Atlas
     |
     v
Managed Database

Local MongoDB vs Atlas

FeatureLocal MongoDBMongoDB Atlas
InstallationRequiredNot required locally
InfrastructureUser-managedManaged service
Local developmentYesYes (connect over network)
Cloud deploymentRequires your infrastructureBuilt for cloud deployments
Server administrationYour responsibilityManaged by the service
Internet dependencyNot necessarilyTypically required

Neither option is required for every learner—choose based on offline needs, ops comfort, and project goals. More on Atlas later.

MongoDB Connection String

Local
mongodb://localhost:27017
mongodb://localhost:27017/mydb
Parts
mongodb://     → connection scheme
localhost      → server on this machine
27017          → default port (configurable)
/mydb          → optional default database name

Do not put production credentials in tutorials. A dedicated connection string page can cover auth and Atlas URIs later.

MongoDB Default Port

27017 is MongoDB’s common default port for mongod. It is a default, not a hard requirement. Configuration can change it; clients must match.

MongoDB Data Directory

Idea
mongod
  |
  v
Data directory (dbPath)
  |
  v
MongoDB data files

Paths depend on OS and method. Examples from common package installs: Linux apt often uses /var/lib/mongodb; macOS Homebrew uses a prefix under /usr/local/var/mongodb or /opt/homebrew/var/mongodb. Always confirm in your mongod configuration—do not treat one path as universal.

Configuration File

mongod can use a configuration file for storage, network binding, port, logging, and security. This is illustrative only—not a production template.

yaml
storage:
  dbPath: /path/to/data

net:
  port: 27017
  bindIp: 127.0.0.1

Default binding is often localhost-only. Do not expose MongoDB on public networks without authentication and proper security controls.

Stopping MongoDB

Prefer a graceful stop so the server can flush cleanly.

OSTypical stop
Windows (service)Services console → MongoDB → Stop
macOS (Homebrew)brew services stop mongodb-community@<version>
Linux (systemd)sudo systemctl stop mongod

Do not treat killing the process as the normal shutdown procedure.

Installation Verification Checklist

Checklist
✓ MongoDB Server installed
✓ mongod available (or Atlas deployment ready)
✓ MongoDB running
✓ mongosh available
✓ mongosh connects successfully
✓ ping command succeeds
✓ Document can be inserted
✓ Document can be read

Common Installation Problems

ProblemLikely cause / next step
mongosh not foundShell not installed or not on PATH
mongod not foundServer binaries missing or not on PATH
Connection refusedServer not running, wrong host/port, or network bind issue
Port already in useAnother process (or MongoDB instance) uses the port
Permission errorsData/log directories need correct ownership and permissions
Service fails to startCheck logs and service status; fix root cause before restart loops
Version mismatchKeep server and tools compatible with your target environment

Do not delete database files as a generic “fix.” Investigate logs and configuration first.

Edge Cases & Pitfalls

Common beginner mistakes around MongoDB installation.

shell

mongosh ≠ server

Installing the shell does not install mongod.

gui

Compass ≠ server

Compass is a client. You still need mongod or Atlas.

cloud

Atlas needs no local mongod

Cloud-only learners can skip a local server install.

port

27017 is a default

Configuration can change the port. Clients must match.

state

Installed ≠ running

A finished install does not guarantee the service is started.

os

Commands differ by OS

Do not paste Linux service commands into Windows, or vice versa.

security

Do not expose publicly by default

Avoid binding to the public internet without authentication and hardening.

version

Install steps change by version

Always verify repository URLs and formulas against current official docs.

Performance / Operational Notes

IdeaPractical tip
Many factorsHardware, storage, indexes, config, and workload all matter
Dev ≠ prodDevelopment defaults are not production settings
Official guidanceFollow MongoDB production and security docs for real deployments
StorageDisk performance strongly affects database workloads

Security Notes

  • Do not expose MongoDB directly to the public internet without proper security controls.
  • Use authentication for secured deployments.
  • Configure network binding deliberately (localhost-only is a common safe default for learning).
  • Protect database credentials; do not put production secrets in tutorials.
  • Use TLS where appropriate for production traffic.
  • Follow MongoDB’s official security documentation for production deployments.

Do not bind MongoDB to all interfaces (for example 0.0.0.0) without understanding the exposure risk and enabling authentication.

Cheat Sheet

ItemRemember
mongodMongoDB server process
mongoshMongoDB command-line shell
CompassMongoDB GUI (optional)
AtlasManaged MongoDB cloud service
Default port27017
Local hostlocalhost
Connection URImongodb://localhost:27017
dbShows current database context
show dbsLists available databases
db.runCommand({ ping: 1 })Tests the connection
insertOne()Inserts a document
find()Reads documents

Key Takeaways

  • MongoDB Server runs as the mongod process.
  • mongosh is the CLI shell used to interact with MongoDB.
  • Install locally or use MongoDB Atlas in the cloud.
  • Compass is a GUI client, not the MongoDB server.
  • Default port is commonly 27017; verify after install with ping.
  • Installation steps differ by OS and MongoDB version—use current official docs.
  • Development defaults are not production security settings.

One line: Install and start mongod, connect with mongosh, ping, then insert and find a document—or skip local install and use Atlas.

Frequently Asked Questions

Installation sets up MongoDB Server (the mongod process) so applications and tools can store and retrieve data. You may also install mongosh to run interactive commands.
mongod is the MongoDB server process. It accepts connections, processes database operations, and manages data files on disk.
mongosh is the MongoDB Shell. It connects to a MongoDB deployment and lets you run commands interactively.
You need mongod (or a cloud deployment like Atlas) to store data. mongosh is the usual CLI client for learning and admin tasks; apps usually connect with a driver instead.
MongoDB Community Edition can be downloaded for free under MongoDB's Community licensing terms. Check the official MongoDB license for your use case. Enterprise Edition is a separate product.
The common default is 27017. Configuration can change the port, and clients must use the configured value.
It depends on the OS and install method. Common patterns: Windows Services console for the MongoDB service; brew services start mongodb-community@<version> on macOS Homebrew; sudo systemctl start mongod on Linux package installs.
Prefer a graceful stop: stop the Windows MongoDB service, brew services stop mongodb-community@<version> on macOS Homebrew, or sudo systemctl stop mongod on Linux. Avoid killing the process as the normal method.
Connect with mongosh and run db.runCommand({ ping: 1 }). A successful response means the server is reachable. You can also check the OS service status when MongoDB runs as a service.
With a local default install, run mongosh (connects to mongodb://localhost:27017). Use a URI if the host or port differs.
No. Compass is an optional GUI client. It does not replace MongoDB Server and is not required to install or run mongod.
No. Atlas is MongoDB's managed cloud service. Local mongod and Atlas are alternate ways to run MongoDB.
Yes. Current Community docs cover Windows using the MSI installer (and other methods). Check the official Windows tutorial for supported Windows versions for your MongoDB release.
Yes. The current Community docs recommend Homebrew for macOS (with platform requirements such as a supported macOS version). See the official macOS tutorial for your MongoDB version.
Yes. Use MongoDB's official apt repository and the mongodb-org packages—not Ubuntu's unofficial mongodb package. Exact repository setup depends on Ubuntu LTS release and MongoDB version.
Yes. MongoDB provides Docker-based installation options in the official documentation. Treat container networking and data volumes carefully.
In a configured data directory (dbPath). Defaults differ by OS and install method—for example, many Linux package installs use /var/lib/mongodb. Always check your mongod configuration.
Usually mongod is not running, or the host/port is wrong. Start the server, confirm the port, then reconnect.
The server binaries may not be installed, or their directory is not on your PATH. Finish the OS install and reopen the terminal.
Yes. Set net.port in the configuration file (or use command-line options). Update every client connection string to match.

Next: MongoDB Operators

Learn the $ operators used in queries, updates, and aggregation.

Operators tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful