MongoDB Installation

What Is MongoDB Installation?
Installing MongoDB means setting up the MongoDB server so applications can store and retrieve data from a MongoDB database.
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.
| Option | Description |
|---|---|
| Local installation | Run MongoDB Server (mongod) on your computer or server |
| MongoDB Atlas | Use MongoDB as a managed cloud service (no local server required) |
| Docker | Run MongoDB in a container (official Docker docs) |
| MongoDB Compass | GUI 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:
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
Your Application
|
v
MongoDB Driver
|
v
mongod
|
v
MongoDB Database 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).
Official Download & Installation Links
Use MongoDB’s current official pages for downloads and OS-specific steps. Package names and supported platforms can change between releases.
| Resource | Official link |
|---|---|
| Installation hub | mongodb.com/docs/manual/installation |
| Community Edition install overview | Install MongoDB Community Edition |
| Download Community Server | MongoDB Community Edition download |
| Community package releases | Community Edition releases |
| Windows install tutorial | Install Community on Windows |
| macOS install tutorial | Install Community on macOS |
| Linux install tutorials | Install Community on Linux |
Install mongosh | Install MongoDB Shell · Download mongosh |
| Download Compass | MongoDB Compass download |
| MongoDB Atlas | Atlas documentation · Create an Atlas account |
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.
Download MongoDB MSI
↓
Install MongoDB Server
↓
Install mongosh separately
↓
Start MongoDB (service or manual)
↓
Connect with mongosh - Download the Community .msi for Windows from the Community Edition download page.
- Run the wizard (Complete is fine for most beginners).
- Optionally install MongoDB as a Windows service so it starts with Windows.
- Compass can be selected in the wizard—optional, not required. You can also download Compass separately.
- Install
mongoshseparately (the MSI does not include it)—see the mongosh install docs or download 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 A successful shell connection means a MongoDB deployment is reachable on the host/port you used (default local URI: mongodb://localhost:27017).
macOS Installation
Current Community docs recommend Homebrew (Homebrew install guide). macOS does not include Homebrew by default. Follow the official macOS installation tutorial for your MongoDB version. Package downloads are also on the Community Edition download page. A dedicated macOS installation page can hold full detail later.
Install Xcode CLT + Homebrew
↓
brew tap mongodb/brew
↓
Install mongodb-community@<version>
↓
Start mongod
↓
Connect with mongosh # Prerequisites (once)
xcode-select --install
# Then install Homebrew from https://brew.sh
brew tap mongodb/brew
brew trust mongodb/brew
brew update
# Example for current docs — replace 9.0 with your target version
brew install [email protected]
# Start / stop as a service
brew services start [email protected]
brew services stop [email protected] Homebrew Community installs typically include mongod and mongosh. Data and config paths differ for Intel vs Apple Silicon (under /usr/local or /opt/homebrew). Use brew --prefix if you need the active prefix.
Ubuntu / Linux Installation
Linux installs commonly use MongoDB’s official package repository and the mongodb-org packages. Exact repository lines depend on Ubuntu/Debian/RHEL release, MongoDB version, and CPU architecture—copy them from the official Linux Community installation tutorials (Ubuntu, Debian, RHEL/Rocky/AlmaLinux, and more). Overview: Install MongoDB Community Edition. A dedicated Ubuntu installation page can expand this later.
Add official MongoDB repository
↓
Install mongodb-org packages
↓
Start mongod (systemd)
↓
Enable service (optional)
↓
Connect with mongosh # After adding the official repo for your Ubuntu + MongoDB version:
sudo apt update
sudo apt install -y mongodb-org
# systemd (common on modern Ubuntu)
sudo systemctl start mongod
sudo systemctl status mongod
sudo systemctl enable mongod # start on boot (optional) Prefer MongoDB’s mongodb-org packages over Ubuntu’s unofficial mongodb package. RHEL / Rocky / AlmaLinux use yum/dnf with an official .repo file—see the Red Hat tutorial for your version.
Starting MongoDB
Service-based
|
v
OS manages mongod
Manual
|
v
You start mongod directly | OS | Typical 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
db.runCommand({ ping: 1 }) { ok: 1 } How It Works
mongoshattempts to connect to MongoDB (default local host/port).db.runCommand({ ping: 1 })sends a ping command to the server.- A response with
ok: 1means the connection is working.
First MongoDB Commands
After connect, try a tiny write/read cycle.
db
show dbs
db.test.insertOne({
message: "MongoDB is working"
})
db.test.find() How It Works
dbshows the current database context.show dbslists databases visible to you.insertOne()creates a document in thetestcollection.find()reads the documents back—full write/read cycle complete.
MongoDB Installation Walkthrough
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.
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.
Local MongoDB
Your Computer
|
v
mongod
|
v
Database
MongoDB Atlas
Your Application
|
v
Internet
|
v
MongoDB Atlas
|
v
Managed Database Local MongoDB vs Atlas
| Feature | Local MongoDB | MongoDB Atlas |
|---|---|---|
| Installation | Required | Not required locally |
| Infrastructure | User-managed | Managed service |
| Local development | Yes | Yes (connect over network) |
| Cloud deployment | Requires your infrastructure | Built for cloud deployments |
| Server administration | Your responsibility | Managed by the service |
| Internet dependency | Not necessarily | Typically 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
mongodb://localhost:27017
mongodb://localhost:27017/mydb 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
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.
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.
| OS | Typical 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
✓ 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
| Problem | Likely cause / next step |
|---|---|
mongosh not found | Shell not installed or not on PATH |
mongod not found | Server binaries missing or not on PATH |
| Connection refused | Server not running, wrong host/port, or network bind issue |
| Port already in use | Another process (or MongoDB instance) uses the port |
| Permission errors | Data/log directories need correct ownership and permissions |
| Service fails to start | Check logs and service status; fix root cause before restart loops |
| Version mismatch | Keep 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.
mongosh ≠ server
Installing the shell does not install mongod.
Compass ≠ server
Compass is a client. You still need mongod or Atlas.
Atlas needs no local mongod
Cloud-only learners can skip a local server install.
27017 is a default
Configuration can change the port. Clients must match.
Installed ≠ running
A finished install does not guarantee the service is started.
Commands differ by OS
Do not paste Linux service commands into Windows, or vice versa.
Do not expose publicly by default
Avoid binding to the public internet without authentication and hardening.
Install steps change by version
Always verify repository URLs and formulas against current official docs.
Performance / Operational Notes
| Idea | Practical tip |
|---|---|
| Many factors | Hardware, storage, indexes, config, and workload all matter |
| Dev ≠ prod | Development defaults are not production settings |
| Official guidance | Follow MongoDB production and security docs for real deployments |
| Storage | Disk 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
| Item | Remember |
|---|---|
mongod | MongoDB server process |
mongosh | MongoDB command-line shell |
| Compass | MongoDB GUI (optional) |
| Atlas | Managed MongoDB cloud service |
| Default port | 27017 |
| Local host | localhost |
| Connection URI | mongodb://localhost:27017 |
db | Shows current database context |
show dbs | Lists available databases |
db.runCommand({ ping: 1 }) | Tests the connection |
insertOne() | Inserts a document |
find() | Reads documents |
Key Takeaways
- MongoDB Server runs as the
mongodprocess. mongoshis 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 withping. - 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
Next: MongoDB Operators
Learn the $ operators used in queries, updates, and aggregation.
9 people found this page helpful
