Type something to search...
How to Install MongoDB on Windows, macOS, and Linux

How to Install MongoDB on Windows, macOS, and Linux

Installing MongoDB used to be a single download that gave you the server, the shell, and a handful of command-line tools. That's no longer the case. The server, the shell (mongosh), and the import/export tools now ship as separate packages, which is why so many first installs end with "mongod is running, but the mongo command isn't found."

The good news is that once you know which pieces you need, a local install is quick on every platform. Each operating system has a preferred path: the MSI installer on Windows, Homebrew on macOS, and the official package repositories on Linux. There's also Docker, which skips the host install entirely and is often the best choice for development.

This guide covers what each MongoDB package does, step-by-step installation on Windows, macOS, and the major Linux distributions, how to verify and connect, where the config and data files live, and the security settings you should change before the database holds anything real.

What You're Actually Installing

Before you download anything, it helps to know the parts:

ComponentWhat it isDo you need it?
mongodThe database server processYes
mongoshThe interactive MongoDB ShellYes, for most workflows
MongoDB Database Toolsmongodump, mongorestore, mongoimport, mongoexport, and friendsFor backups and imports
MongoDB CompassA desktop GUI for browsing and editing dataOptional
mongosThe query router for sharded clustersOnly for sharding

The legacy mongo shell was removed years ago. If a tutorial tells you to type mongo, use mongosh instead; the commands are nearly identical.

You'll also choose between Community Edition (free, source-available, what this guide installs) and Enterprise Edition (commercial, adds features like LDAP, Kerberos, auditing, and encryption at rest). For learning and most applications, Community is the right choice.

At the time of writing, the current major release is MongoDB 8.0. The commands below use 8.0 in package names and URLs; if a newer version is out when you read this, check the official install page and swap in the new version number.

Installing on Windows

Using the MSI Installer

  1. Go to the MongoDB Community Server download page, choose the latest version, Windows x64, and the msi package.
  2. Run the installer and pick Complete setup.
  3. On the service configuration screen, leave Install MongoD as a Service checked. The defaults run it as the Network Service user, with data in C:\Program Files\MongoDB\Server\8.0\data\ and logs in C:\Program Files\MongoDB\Server\8.0\log\.
  4. Optionally check Install MongoDB Compass.
  5. Finish the install.

The installer doesn't include mongosh or the Database Tools. Download each from its own page (both offer MSI installers), or use winget if you prefer the command line:

winget install MongoDB.Server
winget install MongoDB.Shell
winget install MongoDB.DatabaseTools

Package identifiers on winget occasionally change, so if one of those fails, run winget search mongodb to find the current names.

Checking the Windows Service

The server runs as a Windows service named MongoDB. You can manage it from the Services app, or from an elevated PowerShell prompt:

Get-Service MongoDB
Stop-Service MongoDB
Start-Service MongoDB

Adding the Binaries to PATH

The MSI doesn't always add MongoDB to your PATH. If mongod --version isn't recognized, add C:\Program Files\MongoDB\Server\8.0\bin to your user or system PATH through System Properties > Environment Variables, then open a new terminal. The mongosh MSI typically handles its own PATH entry.

The Windows config file is C:\Program Files\MongoDB\Server\8.0\bin\mongod.cfg. Restart the service after editing it.

Installing on macOS

On macOS, the supported route is Homebrew using MongoDB's own tap. It works on both Apple silicon and Intel Macs.

# Install Xcode command-line tools if you haven't already
xcode-select --install

# Add MongoDB's tap and install the server
brew tap mongodb/brew
brew update
brew install mongodb-community@8.0

This formula installs mongod, mongosh, and the Database Tools as dependencies, so you get everything in one step.

Start MongoDB as a background service that also launches at login:

brew services start mongodb-community@8.0

Check it's running:

brew services list
Name                  Status  User  File
mongodb-community@8.0 started maria ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community@8.0.plist

If you'd rather run it only when you need it, skip the service and start it in the foreground with the Homebrew config file:

mongod --config /opt/homebrew/etc/mongod.conf

Paths depend on your chip. On Apple silicon, Homebrew lives in /opt/homebrew; on Intel it's /usr/local:

ItemApple siliconIntel
Config file/opt/homebrew/etc/mongod.conf/usr/local/etc/mongod.conf
Data/opt/homebrew/var/mongodb/usr/local/var/mongodb
Logs/opt/homebrew/var/log/mongodb/usr/local/var/log/mongodb

If macOS blocks mongod with a security warning the first time, open System Settings > Privacy & Security and allow it. That's rare with Homebrew installs, but it happens with manually downloaded tarballs.

Installing on Linux

On Linux, always use MongoDB's official repository rather than the mongodb package your distribution may ship. Distribution packages are often years out of date or no longer maintained.

Ubuntu

These steps target Ubuntu 24.04 (Noble). For 22.04, replace noble with jammy.

# Prerequisites
sudo apt-get install -y gnupg curl

# Import MongoDB's public GPG key
curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \
  sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor

# Add the repository
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | \
  sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list

# Install
sudo apt-get update
sudo apt-get install -y mongodb-org

The mongodb-org metapackage pulls in the server, mongos, mongosh, and the Database Tools.

Debian

Debian uses the same pattern with a different repository line. For Debian 12 (Bookworm):

echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main" | \
  sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list

Import the key exactly as shown for Ubuntu, then run apt-get update and apt-get install -y mongodb-org.

RHEL, Rocky Linux, AlmaLinux, and Amazon Linux

On Red Hat-family systems, create a repo file at /etc/yum.repos.d/mongodb-org-8.0.repo:

[mongodb-org-8.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/8.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://pgp.mongodb.com/server-8.0.asc

Then install:

sudo dnf install -y mongodb-org

Amazon Linux 2023 uses a slightly different baseurl (https://repo.mongodb.org/yum/amazon/2023/mongodb-org/8.0/x86_64/). Check the official docs for your exact distribution and CPU architecture, especially on ARM.

Starting the Service with systemd

On every supported Linux distribution, the package installs a mongod systemd unit:

sudo systemctl start mongod
sudo systemctl enable mongod   # start on boot
sudo systemctl status mongod
● mongod.service - MongoDB Database Server
     Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled)
     Active: active (running) since Tue 2026-09-16 08:10:42 UTC; 5s ago

If the service fails to start with a "status=14" or permission error, the usual culprit is ownership of the data or log directory. The service runs as the mongod user (on Ubuntu, mongodb), so fix ownership accordingly:

sudo chown -R mongodb:mongodb /var/lib/mongodb /var/log/mongodb

Default Linux paths are /etc/mongod.conf for config, /var/log/mongodb/mongod.log for logs, and /var/lib/mongodb (Debian/Ubuntu) or /var/lib/mongo (RHEL family) for data.

The Docker Alternative

If you just need MongoDB for local development, Docker is often the cleanest option. Nothing is installed on your host except the container, and switching versions is a one-line change.

docker run -d \
  --name mongodb \
  -p 27017:27017 \
  -v mongodb-data:/data/db \
  -e MONGO_INITDB_ROOT_USERNAME=admin \
  -e MONGO_INITDB_ROOT_PASSWORD=change-me \
  mongo:8.0

The named volume mongodb-data keeps your data when the container is removed, and the two environment variables create a root user on first start. Connect from the host with:

mongosh "mongodb://admin:change-me@localhost:27017/?authSource=admin"

For multi-service setups with Compose, replica sets in containers, and init scripts, see Running MongoDB in Docker and Docker Compose.

Verifying the Installation

Whichever platform you used, run the same checks.

Check the versions:

mongod --version
mongosh --version
mongodump --version

Connect with the shell. With no arguments, mongosh connects to mongodb://127.0.0.1:27017:

mongosh

Then run a quick round trip:

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

use installcheck
db.hello.insertOne({ msg: "it works", at: new Date() })
db.hello.findOne()
{
  _id: ObjectId('66f7f0a2b5c4d3e2f1a0b9c8'),
  msg: 'it works',
  at: ISODate('2026-09-16T08:14:02.311Z')
}

Once you're satisfied, clean up with db.dropDatabase().

Understanding the Config File

All three platforms use the same YAML config format. A typical development config looks like this:

storage:
  dbPath: /var/lib/mongodb

systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

net:
  port: 27017
  bindIp: 127.0.0.1

processManagement:
  timeZoneInfo: /usr/share/zoneinfo

The settings you're most likely to touch:

  • storage.dbPath is where data files live. Put it on a fast disk with room to grow.
  • net.bindIp controls which network interfaces MongoDB listens on. The default, 127.0.0.1, means only local connections are accepted.
  • security.authorization turns on access control (covered next).
  • replication.replSetName makes the server a replica set member, which you need for transactions and change streams, even on a single node.

After any change, restart the service (systemctl restart mongod, brew services restart mongodb-community@8.0, or Restart-Service MongoDB).

Securing a Fresh Install

A default install accepts connections from localhost without a password. That's convenient on a laptop and dangerous anywhere else. Before you expose the server to a network, enable authentication.

First, create an administrative user while auth is still off:

use admin
db.createUser({
  user: "admin",
  pwd: passwordPrompt(),
  roles: [{ role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase"]
})

passwordPrompt() asks for the password interactively so it doesn't end up in your shell history. Next, enable authorization in the config file:

security:
  authorization: enabled

Restart the server and connect with credentials:

mongosh "mongodb://admin@localhost:27017/?authSource=admin"

Then create a separate, less privileged user for your application, scoped to its own database with the readWrite role. Only after auth is on should you change bindIp to include a private network address, and even then, put a firewall in front of port 27017.

Common Problems and Fixes

"mongo: command not found". The legacy shell no longer exists. Install and use mongosh.

"Connection refused" on port 27017. The server isn't running or is bound to a different interface. Check the service status and read the last lines of the log file; the log almost always states the exact reason.

The service starts, then immediately stops. Look for permission problems on dbPath or the log directory, a port that's already in use, or a YAML indentation error in the config file. YAML requires spaces, not tabs.

"Illegal instruction" or a crash on startup on older hardware. Recent MongoDB versions require CPU features like AVX on x86_64. Very old CPUs and some virtualized environments don't expose them. Use a newer machine, enable CPU passthrough in your hypervisor, or run MongoDB Atlas instead.

Installing the distribution's own mongodb package. It's likely outdated. Remove it and use the official mongodb-org repository.

Running out of disk space in /var. Data files, journal, and logs all grow over time, and the log file keeps growing unless you set up rotation. On servers, mount dbPath on a dedicated volume.

Conclusion

A working MongoDB install comes down to three pieces: the mongod server, the mongosh shell, and the Database Tools. On Windows, use the MSI (or winget) and let it run as a service. On macOS, use MongoDB's Homebrew tap. On Linux, add the official repository and manage the server with systemd. Or skip the host install and run the official image in Docker. In every case, verify with mongosh and a ping, and turn on authentication before the server touches a network.

For your next step, open mongosh, create a database, and insert a few documents of your own. If you'd rather not manage a server at all, set up a free cluster in the cloud with Getting Started with MongoDB Atlas.

Tags :
Share :

Related Posts

A Complete Guide to MongoDB Query Operators

A Complete Guide to MongoDB Query Operators

Your first MongoDB queries are usually simple equality filters: find the user with this email, find orders with this status. That covers a surprising

Continue Reading
Async MongoDB in Python with Motor and FastAPI

Async MongoDB in Python with Motor and FastAPI

FastAPI runs your endpoints on an event loop. That's what lets a single worker juggle hundreds of concurrent requests: while one request waits on the

Continue Reading
Atlas Online Archive: Tiering Cold Data to Cut Costs

Atlas Online Archive: Tiering Cold Data to Cut Costs

Look at almost any production database and you'll find the same shape. A small slice of recent data gets nearly all the reads and writes: this week's

Continue Reading