Install MongoDB¶
Author: MongoDB Documentation Team
This guide describes how to install MongoDB locally. If you would
like to use MongoDB in the Cloud using Atlas
, our managed
database product, see Get Started with Atlas.
Time required: 10 minutes
What You’ll Need¶
MongoDB supports a variety of 64-bit platforms. Refer to the Supported Platforms table to verify that MongoDB is supported on the platform to which you wish to install it.
Procedure¶
Install MongoDB¶
- Windows
- macOS
- Linux
Download the binaries from the MongoDB Download Center.
Open Windows Explorer/File Explorer.
Change the directory path to where you downloaded the MongoDB
.msi
file. By default, this is%HOMEPATH%\Downloads
.Double-click the
.msi
file.The Windows Installer guides you through the installation process.
If you choose the Custom installation option, you may specify an installation directory.
MongoDB does not have any other system dependencies. You can install and run MongoDB from any folder you choose.
Note
This tutorial assumes that you installed MongoDB in
C:\Program Files\MongoDB\Server\4.2\
.
Platform Support
MongoDB only supports macOS versions 10.11 and later on Intel x86-64.
Download the binary files for the desired release of MongoDB.¶
Download the binaries from the MongoDB Download Center.
Extract the files from the downloaded archive.¶
For example, from a system shell, you can extract through the tar
command:
Copy the extracted archive to the target directory.¶
Copy the extracted folder to the location from which MongoDB will run.
Ensure the location of the binaries is in the PATH
variable.¶
The MongoDB binaries are in the bin/
directory of the archive. To
ensure that the binaries are in your PATH
, you can modify your
PATH
.
For example, you can add the following line to your shell’s
rc
file (e.g. ~/.bashrc
):
Replace <mongodb-install-directory>
with the path to the extracted
MongoDB archive.
Note
These instructions are for installing MongoDB directly from an archive file. If you would rather use your linux distribution’s package manager, refer to the installation instructions for your distribution in the MongoDB Manual.
Download the binary files for the desired release of MongoDB.¶
Download the binaries from the MongoDB Download Center.
Extract the files from the downloaded archive.¶
Extract the archive by double-clicking on the tar file or using
the tar
command from the command line, as in the following:
Copy the extracted archive to the target directory.¶
Copy the extracted folder to the location from which MongoDB will run.
Ensure the location of the binaries is in the PATH
variable.¶
The MongoDB binaries are in the bin/
directory of the archive. To
ensure that the binaries are in your PATH
, you can modify your
PATH
.
For example, you can add the following line to your shell’s
rc
file (e.g. ~/.bashrc
):
Replace <mongodb-install-directory>
with the path to the extracted
MongoDB archive.
Run MongoDB¶
- Windows
- macOS
- Linux
Warning
Do not make mongod.exe
visible on public
networks without running in “Secure Mode” with the
auth
setting. MongoDB is designed to be run in
trusted environments, and the database does not enable
“Secure Mode” by default.
Set up the MongoDB environment.¶
MongoDB requires a data directory to store all
data. MongoDB’s default data directory path is the absolute path
\data\db
on the drive from which you start MongoDB. Create
this folder by running the following command in a
Command Prompt:
You can specify an alternate path for data files using the
--dbpath
option to
mongod.exe
, for example:
If your path includes spaces, enclose the entire path in double quotes, for example:
You may also specify the dbpath
in a configuration file.
Start MongoDB.¶
To start MongoDB, run mongod.exe
. For example, from the
Command Prompt:
This starts the main MongoDB database process. The waiting for
connections
message in the console output indicates that the
mongod.exe
process is running successfully.
Depending on the security level of your system, Windows may pop up a
Security Alert dialog box about blocking “some features” of
C:\Program Files\MongoDB\Server\4.0\bin\mongod.exe
from communicating
on networks. All users should select Private Networks, such as my home or
work network
and click Allow access
. For additional information on
security and MongoDB, please see the Security Documentation.
Verify that MongoDB has started successfully¶
Verify that MongoDB has started successfully by checking the process output for the following line:
The output should be visible in the terminal or shell window.
You may see non-critical warnings in the process output. As long as you see the log line shown above, you can safely ignore these warnings during your initial evaluation of MongoDB.
Connect to MongoDB.¶
To connect to MongoDB through the ~bin.mongo.exe
shell,
open another Command Prompt.
Create the data directory¶
Before you start MongoDB for the first time, create the directory to
which the mongod
process will write data. By default, the
mongod
process uses the /data/db
directory. If you create
a directory other than this one, you must specify that directory in the
dbpath
option when starting the mongod
process
later in this procedure.
The following example command creates the default /data/db
directory:
Run MongoDB¶
To run MongoDB, run the mongod
process at the system prompt.
If necessary, specify the path of the mongod
or the data
directory. See the following examples.
Run without specifying paths¶
If your system PATH
variable includes the location of the
mongod
binary and if you use the default data directory
(i.e., /data/db
), simply enter mongod
at the system prompt:
Verify that MongoDB has started successfully¶
Verify that MongoDB has started successfully by checking the process output for the following line:
The output should be visible in the terminal or shell window.
You may see non-critical warnings in the process output. As long as you see the log line shown above, you can safely ignore these warnings during your initial evaluation of MongoDB.
Important
If you are using SELinux on a Red Hat Linux-based system, (Red Hat Enterprise Linux or CentOS Linux), you must configure SELinux to allow MongoDB to start. Refer to Configure SELinux for instructions.
Create the data directory¶
Before you start MongoDB for the first time, create the directory to
which the mongod
process will write data. By default, the
mongod
process uses the /data/db
directory. If you create
a directory other than this one, you must specify that directory in the
dbpath
option when starting the mongod
process
later in this procedure.
The following example command creates the default /data/db
directory:
Run MongoDB¶
To run MongoDB, run the mongod
process at the system prompt.
If necessary, specify the path of the mongod
or the data
directory. See the following examples.
Run without specifying paths¶
If your system PATH
variable includes the location of the
mongod
binary and if you use the default data directory
(i.e., /data/db
), simply enter mongod
at the system prompt:
Verify that MongoDB has started successfully¶
Verify that MongoDB has started successfully by checking the process output for the following line:
The output should be visible in the terminal or shell window.
You may see non-critical warnings in the process output. As long as you see the log line shown above, you can safely ignore these warnings during your initial evaluation of MongoDB.
Summary¶
If you have successfully completed this guide, you have installed
MongoDB and are ready to connect to your mongod
instance and start inserting data.
What’s Next¶
The next guide walks you through setting up authentication on your new MongoDB instance.
See Also¶
- Structure your Data for MongoDB for an introduction to MongoDB.
- Installation for installation instructions for MongoDB Enterprise Edition, details on installing older versions of MongoDB.