Select your distribution to view installation instructions for MongoDB Community Edition.
Note
By default, MongoDB Community Edition does not include MongoDB Search. To use MongoDB Search with MongoDB Community, you must install MongoDB Search with Docker or Linux separately.
Install MongoDB Community Edition on Red Hat or CentOS
Overview
Use this tutorial to install MongoDB 9.0 Community Edition on Red Hat Enterprise Linux, CentOS Linux, or Oracle Linux [1] using the YUM package manager.
MongoDB Version
This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.
Considerations
Platform Support
MongoDB 9.0 Community Edition supports the following 64-bit versions of Red Hat Enterprise Linux (RHEL), CentOS Linux, Oracle Linux [1], Rocky Linux, and AlmaLinux [2] on x86_64 architecture:
RHEL / CentOS Stream / Oracle / Rocky / AlmaLinux 10
RHEL / CentOS Stream / Oracle / Rocky / AlmaLinux 9
RHEL / CentOS Stream / Oracle / Rocky / AlmaLinux 8
MongoDB only supports the 64-bit versions of these platforms.
MongoDB 9.0 Community Edition on RHEL / CentOS / Oracle / Rocky / AlmaLinux also supports the ARM64 architecture on select platforms.
See Platform Support for more information.
| [1] | (1, 2) MongoDB only supports Oracle Linux running the Red Hat Compatible Kernel (RHCK). MongoDB does not support the Unbreakable Enterprise Kernel (UEK). |
| [2] | MongoDB on-premises products released for RHEL version 8.0+ are compatible with and supported on Rocky Linux version 8.0+ and AlmaLinux version 8.0+, contingent upon those distributions meeting their obligation to deliver full RHEL compatibility. |
Production Notes
Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.
Install MongoDB Community Edition
Follow these steps to install MongoDB Community Edition using the YUM package manager.
Configure the repository.
Create a /etc/yum.repos.d/mongodb-org-9.0.repo file so that you can install MongoDB directly using yum:
[mongodb-org-9.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/10/mongodb-org/9.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://pgp.mongodb.com/server-9.asc
[mongodb-org-9.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/9/mongodb-org/9.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://pgp.mongodb.com/server-9.asc
[mongodb-org-9.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/8/mongodb-org/9.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://pgp.mongodb.com/server-9.asc
You can also download the .rpm files directly from the MongoDB repository. Downloads are organized by Red Hat / CentOS version (e.g. 9), then MongoDB release version (e.g. 9.0), then architecture (e.g. x86_64).
Install MongoDB Community Server.
To install the latest stable version of MongoDB, issue the following command:
sudo yum install -y mongodb-org
Alternatively, to install a specific release of MongoDB, specify each component package individually and append the version number to the package name, as in the following example:
sudo yum install -y mongodb-org-9.0.0 mongodb-org-database-9.0.0 mongodb-org-server-9.0.0 mongodb-mongosh mongodb-org-mongos-9.0.0 mongodb-org-tools-9.0.0
Note
yum automatically upgrades packages when newer versions become available. If you want to prevent MongoDB upgrades, pin the package by adding the following exclude directive to your /etc/yum.conf file:
exclude=mongodb-org,mongodb-org-database,mongodb-org-server,mongodb-mongosh,mongodb-org-mongos,mongodb-org-tools
Run MongoDB Community Edition
ulimit
Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.
Note
If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.
Directory Paths
To Use Default Directories
For details on default directories, see Default Data and Log Directory Paths.
To Use Non-Default Directories
To use a data directory and/or log directory other than the default directories:
Create the new directory or directories.
Edit the configuration file
/etc/mongod.confand modify the following fields accordingly:storage.dbPathto specify a new data directory path (e.g./some/data/directory)systemLog.pathto specify a new log file path (e.g./some/log/directory/mongod.log)
Ensure that the user running MongoDB has access to the directory or directories:
sudo chown -R mongod:mongod <directory> If you change the user that runs the MongoDB process, you must give the new user access to these directories.
Configure SELinux if enforced. See Configure the MongoDB SELinux Policy.
Additional Information
Localhost Binding by Default
By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.
This value can be configured either:
Warning
Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.
For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.
MongoDB Community Edition Packages
For a complete list of packages, see MongoDB Community Edition Packages.
Install MongoDB Community on Red Hat or CentOS using .tgz Tarball
Overview
Use this tutorial to manually install MongoDB 9.0 Community Edition on Red Hat Enterprise Linux, CentOS Linux, or Oracle Linux [1] using a downloaded .tgz tarball.
MongoDB Version
This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.
Installation Method
While you can install MongoDB manually using a downloaded .tgz tarball as described in this document, we recommend using the yum package manager on your system if possible. Using a package manager automatically installs all needed dependencies, provides an example mongod.conf file, and simplifies future upgrade and maintenance tasks.
➤ See Install MongoDB using the yum Package Manager for instructions.
Considerations
MongoDB Shell, mongosh
When you use the .tgz package to install the server, you need to follow the mongosh installation instructions to download and install mongosh separately.
Platform Support
MongoDB 9.0 Community Edition supports the following 64-bit versions of Red Hat Enterprise Linux (RHEL), CentOS Linux, Oracle Linux [1], Rocky Linux, and AlmaLinux [2] on x86_64 architecture:
RHEL / CentOS Stream / Oracle / Rocky / AlmaLinux 10
RHEL / CentOS Stream / Oracle / Rocky / AlmaLinux 9
RHEL / CentOS Stream / Oracle / Rocky / AlmaLinux 8
MongoDB only supports the 64-bit versions of these platforms.
MongoDB 9.0 Community Edition on RHEL / CentOS / Oracle / Rocky / AlmaLinux also supports the ARM64 architecture on select platforms.
See Platform Support for more information.
| [1] | (1, 2, 3, 4) MongoDB only supports Oracle Linux running the Red Hat Compatible Kernel (RHCK). MongoDB does not support the Unbreakable Enterprise Kernel (UEK). |
| [2] | (1, 2) MongoDB on-premises products released for RHEL version 8.0+ are compatible with and supported on Rocky Linux version 8.0+ and AlmaLinux version 8.0+, contingent upon those distributions meeting their obligation to deliver full RHEL compatibility. |
Production Notes
Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.
Install MongoDB Community Edition
Prerequisites
Use the following command to install the required dependencies for the MongoDB Community .tgz tarball:
sudo yum install libcurl openssl xz-libs
Procedure
Follow these steps to manually install MongoDB Community Edition from the .tgz.
Download the tarball.
After you have installed the required prerequisite packages, download the MongoDB Community tgz tarball from the following link:
➤
In the Version dropdown, select the version of MongoDB to download.
In the Platform dropdown, select your operating system version and architecture.
In the Package dropdown, select tgz.
Click Download.
Ensure the binaries are in a directory listed in your PATH environment variable.
The MongoDB binaries are in the bin/ directory of the tarball. You can either:
Copy the binaries into a directory listed in your
PATHvariable, such as/usr/local/bin(Update/path/to/the/mongodb-directory/with your installation directory as appropriate)sudo cp /path/to/the/mongodb-directory/bin/* /usr/local/bin/ Create symbolic links to the binaries from a directory listed in your
PATHvariable, such as/usr/local/bin(Update/path/to/the/mongodb-directory/with your installation directory as appropriate):sudo ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/
Install the MongoDB Shell (mongosh).
Install mongosh then use the MongoDB Shell to connect to your deployment.
Download the package for the version of mongosh you need from the MongoDB Download Center and uncompress the package.
Run MongoDB Community Edition
ulimit
Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.
Note
If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.
Directory Paths
To Use Default Directories
By default, MongoDB runs using the mongod user account and uses the following default directories:
/var/lib/mongo(the data directory)/var/log/mongodb(the log directory)
Create the MongoDB data and log directories:
sudo mkdir -p /var/lib/mongo sudo mkdir -p /var/log/mongodb
By default, MongoDB runs using the mongod user account. Create a mongod and a mongodb group. Ensure that the mongod belongs to the group then set the owner and group of these directories to mongod:
sudo chown -R mongod:mongod /var/lib/mongo sudo chown -R mongod:mongod /var/log/mongodb
To Use Non-Default Directories
To use a data directory and/or log directory other than the default directories:
Create the new directory or directories.
Edit the configuration file
/etc/mongod.confand modify the following fields accordingly:storage.dbPathto specify a new data directory path (e.g./some/data/directory)systemLog.pathto specify a new log file path (e.g./some/log/directory/mongod.log)
Ensure that the user running MongoDB has access to the directory or directories:
sudo chown -R mongod:mongod <directory> If you change the user that runs the MongoDB process, you must give the new user access to these directories.
Configure SELinux if enforced. See Configure the MongoDB SELinux Policy.
Procedure
Follow these steps to run MongoDB Community Edition on your system. These instructions assume that you are using the default settings.
Create the data and log directories.
Create a directory where the MongoDB instance stores its data. For example:
sudo mkdir -p /var/lib/mongo
Create a directory where the MongoDB instance stores its log. For example:
sudo mkdir -p /var/log/mongodb
The user that starts the MongoDB process must have read and write permission to these directories. For example, if you intend to run MongoDB as yourself:
sudo chown `whoami` /var/lib/mongo # Or substitute another user sudo chown `whoami` /var/log/mongodb # Or substitute another user
Verify that MongoDB has started successfully.
Verify that MongoDB has started successfully by checking the process output for the following line in the log file /var/log/mongodb/mongod.log:
[initandlisten] waiting for connections on port 27017
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.
Begin using MongoDB.
Start a mongosh session on the same host machine as the mongod. You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with default port 27017.
mongosh
For more information on connecting using mongosh, such as to connect to a mongod instance running on a different host and/or port, see the mongosh documentation.
To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.
Additional Information
Localhost Binding by Default
By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.
This value can be configured either:
Warning
Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.
For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.
Install MongoDB Community Edition on Ubuntu
Overview
Use this tutorial to install MongoDB 9.0 Community Edition on LTS (long-term support) releases of Ubuntu Linux using the APT package manager.
MongoDB Version
This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.
Considerations
Platform Support
MongoDB 9.0 Community Edition supports the following 64-bit Ubuntu LTS (long-term support) releases on x86_64 architecture:
26.04 LTS ("Resolute")
24.04 LTS ("Noble")
22.04 LTS ("Jammy")
MongoDB only supports the 64-bit versions of these platforms. To determine which Ubuntu release your host is running, run the following command on the host's terminal:
cat /etc/lsb-release
MongoDB 9.0 Community Edition on Ubuntu also supports the ARM64 architecture on select platforms.
See Platform Support for more information.
Production Notes
Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.
Official MongoDB Packages
To install MongoDB Community on your Ubuntu system, these instructions will use the official mongodb-org package, which is maintained and supported by MongoDB Inc. The official mongodb-org package always contains the latest version of MongoDB and is available from its own dedicated repo.
Important
The mongodb package provided by Ubuntu is not maintained by MongoDB Inc. and conflicts with the official mongodb-org package. If you already installed the mongodb package on your Ubuntu system, you must first uninstall the mongodb package before proceeding with these instructions.
See MongoDB Community Edition Packages for the complete list of official packages.
Install MongoDB Community Edition
Follow these steps to install MongoDB Community Edition using the APT package manager.
Import the public key.
From a terminal, install gnupg and curl if they are not already available:
sudo apt-get install gnupg curl
To import the MongoDB public GPG key, run the following command:
curl -fsSL https://pgp.mongodb.com/server-9.asc | \ sudo gpg -o /usr/share/keyrings/mongodb-server-9.gpg \ --dearmor
Create the list file.
Create the list file /etc/apt/sources.list.d/mongodb-org-9.0.list for your version of Ubuntu.
Create the list file for Ubuntu 26.04 (Resolute):
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-9.gpg ] https://repo.mongodb.org/apt/ubuntu resolute/mongodb-org/9.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-9.0.list
Create the list file for Ubuntu 24.04 (Noble):
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-9.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/9.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-9.0.list
Create the list file for Ubuntu 22.04 (Jammy):
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-9.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/9.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-9.0.list
Install MongoDB Community Server.
You can install either the latest stable version of MongoDB or a specific version of MongoDB.
To install the latest stable version, issue the following
sudo apt-get install -y mongodb-org
To install a specific release, you must specify each component package individually along with the version number, as in the following example:
sudo apt-get install -y mongodb-org=9.0.0 mongodb-org-database=9.0.0 mongodb-org-server=9.0.0 mongodb-mongosh mongodb-org-mongos=9.0.0 mongodb-org-tools=9.0.0
If you only install mongodb-org=9.0.0 and do not include the component packages, the latest version of each MongoDB package will be installed regardless of what version you specified.
Optional. Although you can specify any available version of MongoDB, apt-get will upgrade the packages when a newer version becomes available. To prevent unintended upgrades, you can pin the package at the currently installed version:
echo "mongodb-org hold" | sudo dpkg --set-selections echo "mongodb-org-database hold" | sudo dpkg --set-selections echo "mongodb-org-server hold" | sudo dpkg --set-selections echo "mongodb-mongosh hold" | sudo dpkg --set-selections echo "mongodb-org-mongos hold" | sudo dpkg --set-selections echo "mongodb-org-tools hold" | sudo dpkg --set-selections
For help with troubleshooting errors encountered while installing MongoDB on Ubuntu, see our troubleshooting guide.
Run MongoDB Community Edition
ulimit Considerations
Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.
Note
If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.
Directories
For details on default directories, see Default Data and Log Directory Paths.
Procedure
Follow these steps to run MongoDB Community Edition on your system. These instructions assume that you are using the official mongodb-org package -- not the unofficial mongodb package provided by Ubuntu -- and are using the default settings.
Init System
To run and manage your mongod process, use your operating system's built-in init system. Recent versions of Linux use systemd, which uses the systemctl command, while older versions of Linux use System V init, which uses the service command.
If you are unsure which init system your platform uses, run the following command:
ps --no-headers -o comm 1
Then select the appropriate tab below based on the result:
systemd- select the systemd (systemctl) tab below.init- select the System V Init (service) tab below.
Start MongoDB.
You can start the mongod process by issuing the following command:
sudo systemctl start mongod
If you receive an error similar to the following when starting mongod:
Failed to start mongod.service: Unit mongod.service not found.
Run the following command first:
sudo systemctl daemon-reload
Then run the start command above again.
Stop MongoDB.
As needed, you can stop the mongod process by issuing the following command:
sudo systemctl stop mongod
Restart MongoDB.
You can restart the mongod process by issuing the following command:
sudo systemctl restart mongod
You can follow the state of the process for errors or important messages by watching the output in the /var/log/mongodb/mongod.log file.
Begin using MongoDB.
Start a mongosh session on the same host machine as the mongod. You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with default port 27017.
mongosh
For more information on connecting using mongosh, such as to connect to a mongod instance running on a different host and/or port, see the mongosh documentation.
To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.
Start MongoDB.
Issue the following command to start mongod:
sudo service mongod start
Verify that MongoDB has started successfully
Verify that the mongod process has started successfully:
sudo service mongod status
You can also check the log file for the current status of the mongod process, located at: /var/log/mongodb/mongod.log by default. A running mongod instance will indicate that it is ready for connections with the following line:
[initandlisten] waiting for connections on port 27017
Stop MongoDB.
As needed, you can stop the mongod process by issuing the following command:
sudo service mongod stop
Restart MongoDB.
Issue the following command to restart mongod:
sudo service mongod restart
Begin using MongoDB.
Start a mongosh session on the same host machine as the mongod. You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with default port 27017.
mongosh
For more information on connecting using mongosh, such as to connect to a mongod instance running on a different host and/or port, see the mongosh documentation.
To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.
Additional Information
Localhost Binding by Default
By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.
This value can be configured either:
Warning
Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.
For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.
MongoDB Community Edition Packages
For a complete list of packages, see MongoDB Community Edition Packages.
Install MongoDB Community on Ubuntu using .tgz Tarball
Overview
Use this tutorial to manually install MongoDB 9.0 Community Edition on LTS (long-term support) releases of Ubuntu Linux using a downloaded .tgz tarball.
MongoDB Version
This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.
Installation Method
While you can install MongoDB manually using a downloaded .tgz tarball as described in this document, we recommend using the apt package manager on your system if possible. Using a package manager automatically installs all needed dependencies, provides an example mongod.conf file, and simplifies future upgrade and maintenance tasks.
➤ See Install MongoDB using the apt Package Manager for instructions.
Considerations
MongoDB Shell, mongosh
When you use the .tgz package to install the server, you need to follow the mongosh installation instructions to download and install mongosh separately.
Platform Support
MongoDB 9.0 Community Edition supports the following 64-bit Ubuntu LTS (long-term support) releases on x86_64 architecture:
26.04 LTS ("Resolute")
24.04 LTS ("Noble")
22.04 LTS ("Jammy")
MongoDB only supports the 64-bit versions of these platforms. To determine which Ubuntu release your host is running, run the following command on the host's terminal:
cat /etc/lsb-release
MongoDB 9.0 Community Edition on Ubuntu also supports the ARM64 architecture on select platforms.
See Platform Support for more information.
Production Notes
Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.
Install MongoDB Community Edition
Prerequisites
Use the following command to install the required dependencies for the MongoDB Community .tgz tarball:
sudo apt-get install libcurl4 libgssapi-krb5-2 libldap2 libwrap0 libsasl2-2 libsasl2-modules libsasl2-modules-gssapi-mit openssl liblzma5
sudo apt-get install libcurl4 libgssapi-krb5-2 libldap2 libwrap0 libsasl2-2 libsasl2-modules libsasl2-modules-gssapi-mit openssl liblzma5
sudo apt-get install libcurl4 libgssapi-krb5-2 libldap-2.5-0 libwrap0 libsasl2-2 libsasl2-modules libsasl2-modules-gssapi-mit openssl liblzma5
Procedure
Follow these steps to manually install MongoDB Community Edition from the .tgz.
Download the tarball.
After you have installed the required prerequisite packages, download the MongoDB Community tgz tarball from the following link:
➤
In the Version dropdown, select the version of MongoDB to download.
In the Platform dropdown, select your operating system version and architecture.
In the Package dropdown, select tgz.
Click Download.
Extract the files from the downloaded archive.
Using an archive manager program or the tar command, extract the files.
For example, to extract from the terminal shell, you can use the following tar command:
Tip
If you downloaded a different MongoDB 9.0 point release, be sure to modify the command to reflect the correct .tgz file name.
tar -zxvf mongodb-linux-*-9.0.0.tgz
Optional. Ensure the binaries are in a directory listed in your PATH environment variable.
The MongoDB binaries are in the <mongodb-install-directory>/bin/ directory.
To avoid having to specify the path to the MongoDB binaries, you can create symbolic links to the binaries from a directory listed in your PATH variable, such as /usr/local/bin. Update /path/to/the/mongodb-directory/ with your installation directory as appropriate.
sudo ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/
Alternatively, you can copy these binaries into a directory listed in your PATH variable such as /usr/local/bin.
sudo cp <mongodb-install-directory>/bin/* /usr/local/bin/
Install the MongoDB Shell (mongosh).
Install mongosh then use the MongoDB Shell to connect to your deployment.
Download the package for the version of mongosh you need from the MongoDB Download Center and uncompress the package.
Run MongoDB Community Edition
ulimit Considerations
Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.
Note
If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.
Configuration
You can configure the MongoDB instance (such as the data directory and log directory specifications) using either the command-line options or a configuration file.
Procedure
Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings.
Create the data and log directories.
Create a directory where the MongoDB instance stores its data. For example:
sudo mkdir -p /var/lib/mongo
Create a directory where the MongoDB instance stores its log. For example:
sudo mkdir -p /var/log/mongodb
The user that starts the MongoDB process must have read and write permission to these directories. For example, if you intend to run MongoDB as yourself:
sudo chown `whoami` /var/lib/mongo # Or substitute another user sudo chown `whoami` /var/log/mongodb # Or substitute another user
Verify that MongoDB has started successfully.
Verify that MongoDB has started successfully by checking the process output for the following line in the log file /var/log/mongodb/mongod.log:
[initandlisten] waiting for connections on port 27017
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.
Begin using MongoDB.
Start a mongosh session on the same host machine as the mongod. You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with default port 27017.
mongosh
For more information on connecting using mongosh, such as to connect to a mongod instance running on a different host and/or port, see the mongosh documentation.
To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.
Additional Information
Localhost Binding by Default
By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.
This value can be configured either:
Warning
Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.
For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.
Install MongoDB Community Edition on Debian
Note
MongoDB Atlas
MongoDB Atlas is a hosted MongoDB service option in the cloud which requires no installation overhead and offers a free cluster to get started.
Overview
Use this tutorial to install MongoDB 9.0 Community Edition using the APT package manager.
MongoDB Version
This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.
Considerations
Platform Support
MongoDB 9.0 Community Edition supports the following 64-bit Debian releases on x86_64 architecture:
- Debian 13 "Trixie"
MongoDB only supports the 64-bit versions of these platforms.
See Platform Support for more information.
Production Notes
Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.
Official MongoDB Packages
To install MongoDB Community on your Debian system, these instructions will use the official mongodb-org package, which is maintained and supported by MongoDB Inc. The official mongodb-org package always contains the latest version of MongoDB and is available from its own dedicated repo.
Important
The mongodb package provided by Debian is not maintained by MongoDB Inc. and conflicts with the official mongodb-org package. If you already installed the mongodb package on your Debian system, you must first uninstall the mongodb package before proceeding with these instructions.
See MongoDB Community Edition Packages for the complete list of official packages.
Install MongoDB Community Edition
Follow these steps to install MongoDB Community Edition using the APT package manager.
Import the public key.
From a terminal, install gnupg and curl if they are not already available:
sudo apt-get install gnupg curl
To import the MongoDB public GPG key, run the following command:
curl -fsSL https://pgp.mongodb.com/server-9.asc | \ sudo gpg -o /usr/share/keyrings/mongodb-server-9.gpg \ --dearmor
Install MongoDB Community Server.
You can install either the latest stable version of MongoDB or a specific version of MongoDB.
To install the latest stable version, issue the following
sudo apt-get install -y mongodb-org
To install a specific release, you must specify each component package individually along with the version number, as in the following example:
sudo apt-get install -y mongodb-org=9.0.0 mongodb-org-database=9.0.0 mongodb-org-server=9.0.0 mongodb-mongosh mongodb-org-mongos=9.0.0 mongodb-org-tools=9.0.0
If you only install mongodb-org=9.0.0 and do not include the component packages, the latest version of each MongoDB package will be installed regardless of what version you specified.
Optional. Although you can specify any available version of MongoDB, apt-get will upgrade the packages when a newer version becomes available. To prevent unintended upgrades, you can pin the package at the currently installed version:
echo "mongodb-org hold" | sudo dpkg --set-selections echo "mongodb-org-database hold" | sudo dpkg --set-selections echo "mongodb-org-server hold" | sudo dpkg --set-selections echo "mongodb-mongosh hold" | sudo dpkg --set-selections echo "mongodb-org-mongos hold" | sudo dpkg --set-selections echo "mongodb-org-tools hold" | sudo dpkg --set-selections
Run MongoDB Community Edition
ulimit Considerations
Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.
Note
If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.
Directories
For details on default directories, see Default Data and Log Directory Paths.
Procedure
Follow these steps to run MongoDB Community Edition on your system. These instructions assume that you are using the official mongodb-org package -- not the unofficial mongodb package provided by Debian -- and are using the default settings.
Init System
To run and manage your mongod process, use your operating system's built-in init system. Recent versions of Linux use systemd, which uses the systemctl command, while older versions of Linux use System V init, which uses the service command.
If you are unsure which init system your platform uses, run the following command:
ps --no-headers -o comm 1
Then select the appropriate tab below based on the result:
systemd- select the systemd (systemctl) tab below.init- select the System V Init (service) tab below.
Start MongoDB.
You can start the mongod process by issuing the following command:
sudo systemctl start mongod
If you receive an error similar to the following when starting mongod:
Failed to start mongod.service: Unit mongod.service not found.
Run the following command first:
sudo systemctl daemon-reload
Then run the start command above again.
Stop MongoDB.
As needed, you can stop the mongod process by issuing the following command:
sudo systemctl stop mongod
Restart MongoDB.
You can restart the mongod process by issuing the following command:
sudo systemctl restart mongod
You can follow the state of the process for errors or important messages by watching the output in the /var/log/mongodb/mongod.log file.
Begin using MongoDB.
Start a mongosh session on the same host machine as the mongod. You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with default port 27017.
mongosh
For more information on connecting using mongosh, such as to connect to a mongod instance running on a different host and/or port, see the mongosh documentation.
To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.
Start MongoDB.
Issue the following command to start mongod:
sudo service mongod start
Verify that MongoDB has started successfully
Verify that the mongod process has started successfully:
sudo service mongod status
You can also check the log file for the current status of the mongod process, located at: /var/log/mongodb/mongod.log by default. A running mongod instance will indicate that it is ready for connections with the following line:
[initandlisten] waiting for connections on port 27017
Stop MongoDB.
As needed, you can stop the mongod process by issuing the following command:
sudo service mongod stop
Restart MongoDB.
Issue the following command to restart mongod:
sudo service mongod restart
Begin using MongoDB.
Start a mongosh session on the same host machine as the mongod. You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with default port 27017.
mongosh
For more information on connecting using mongosh, such as to connect to a mongod instance running on a different host and/or port, see the mongosh documentation.
To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.
Additional Information
Localhost Binding by Default
By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.
This value can be configured either:
Warning
Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.
For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.
MongoDB Community Edition Packages
For a complete list of packages, see MongoDB Community Edition Packages.
Install MongoDB Community on Debian using .tgz Tarball
Overview
Use this tutorial to manually install MongoDB 9.0 Community Edition on Debian Linux using a downloaded .tgz tarball.
MongoDB Version
This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.
Installation Method
While you can install MongoDB manually using a downloaded .tgz tarball as described in this document, we recommend using the apt package manager on your system if possible. Using a package manager automatically installs all needed dependencies, provides an example mongod.conf file, and simplifies future upgrade and maintenance tasks.
➤ See Install MongoDB using the apt Package Manager for instructions.
Considerations
MongoDB Shell, mongosh
When you use the .tgz package to install the server, you need to follow the mongosh installation instructions to download and install mongosh separately.
Platform Support
MongoDB 9.0 Community Edition supports the following 64-bit Debian releases on x86_64 architecture:
- Debian 13 "Trixie"
MongoDB only supports the 64-bit versions of these platforms.
See Platform Support for more information.
Production Notes
Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.
Install MongoDB Community Edition
Prerequisites
Use the following command to install the required dependencies for the MongoDB Community .tgz tarball:
sudo apt-get install libcurl4 libgssapi-krb5-2 libldap-common libwrap0 libsasl2-2 libsasl2-modules libsasl2-modules-gssapi-mit openssl liblzma5
Procedure
Follow these steps to manually install MongoDB Community Edition from the .tgz.
Download the tarball.
After you have installed the required prerequisite packages, download the MongoDB Community tgz tarball from the following link:
➤
In the Version dropdown, select the version of MongoDB to download.
In the Platform dropdown, select your operating system version and architecture.
In the Package dropdown, select tgz.
Click Download.
Ensure the binaries are in a directory listed in your PATH environment variable.
The MongoDB binaries are in the bin/ directory of the tarball. You can either:
Copy the binaries into a directory listed in your
PATHvariable, such as/usr/local/bin(Update/path/to/the/mongodb-directory/with your installation directory as appropriate)sudo cp /path/to/the/mongodb-directory/bin/* /usr/local/bin/ Create symbolic links to the binaries from a directory listed in your
PATHvariable, such as/usr/local/bin(Update/path/to/the/mongodb-directory/with your installation directory as appropriate):sudo ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/
Install the MongoDB Shell (mongosh).
Install mongosh then use the MongoDB Shell to connect to your deployment.
Download the package for the version of mongosh you need from the MongoDB Download Center and uncompress the package.
Run MongoDB Community Edition
ulimit Considerations
Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.
Note
If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.
Directories
By default, a MongoDB instance stores:
its data files in
/var/lib/mongodbits log files in
/var/log/mongodb
If you installed using the package manager, these default directories are created during installation.
If you installed manually by downloading the tarballs, create the directories using mkdir -p <directory> or sudo mkdir -p <directory> depending on the user that will run MongoDB. See your linux man pages for information on mkdir and sudo.
By default, MongoDB runs using the mongodb user account. If you change the user that runs the MongoDB process, you must also modify the permission to the /var/lib/mongodb and /var/log/mongodb directories to give this user access to these directories.
To specify a different log file directory and data file directory, edit the systemLog.path and storage.dbPath settings in the /etc/mongod.conf. Ensure that the user running MongoDB has access to these directories.
Procedure
Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings.
Create the data and log directories.
Create a directory where the MongoDB instance stores its data. For example:
sudo mkdir -p /var/lib/mongo
Create a directory where the MongoDB instance stores its log. For example:
sudo mkdir -p /var/log/mongodb
The user that starts the MongoDB process must have read and write permission to these directories. For example, if you intend to run MongoDB as yourself:
sudo chown `whoami` /var/lib/mongo # Or substitute another user sudo chown `whoami` /var/log/mongodb # Or substitute another user
Verify that MongoDB has started successfully.
Verify that MongoDB has started successfully by checking the process output for the following line in the log file /var/log/mongodb/mongod.log:
[initandlisten] waiting for connections on port 27017
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.
Begin using MongoDB.
Start a mongosh session on the same host machine as the mongod. You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with default port 27017.
mongosh
For more information on connecting using mongosh, such as to connect to a mongod instance running on a different host and/or port, see the mongosh documentation.
To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.
Additional Information
Localhost Binding by Default
By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.
This value can be configured either:
Warning
Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.
For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.
Install MongoDB Community Edition on SUSE
Overview
Use this tutorial to install MongoDB 9.0 Community Edition on SUSE Linux Enterprise Server (SLES) using the ZYpp package manager.
MongoDB Version
This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.
Considerations
Platform Support
MongoDB 9.0 Community Edition supports the following 64-bit SUSE Linux Enterprise Server (SLES) releases on x86_64 architecture:
SLES 15
SLES 16
MongoDB only supports the 64-bit versions of these platforms.
See Platform Support for more information.
Production Notes
Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.
Install MongoDB Community Edition
Follow these steps to install MongoDB Community Edition using the ZYpp package manager.
Add the repository.
Select the tab for your version of SUSE:
To add the repository file for SUSE Enterprise Linux 16, run the following command:
sudo zypper addrepo --gpgcheck "https://repo.mongodb.org/zypper/suse/16/mongodb-org/9.0/x86_64/" mongodb
To add the repository file for SUSE Enterprise Linux 15, run the following command:
sudo zypper addrepo --gpgcheck "https://repo.mongodb.org/zypper/suse/15/mongodb-org/9.0/x86_64/" mongodb
Install MongoDB packages.
You can install either the latest stable release of MongoDB or a specific release of MongoDB.
To install the latest version of MongoDB, run the following command:
sudo zypper -n install mongodb-org
To install a specific release of MongoDB, specify each component package individually and append the version number to the package name.
sudo zypper install \ mongodb-org-9.0.0 \ mongodb-org-database-9.0.0 \ mongodb-org-server-9.0.0 \ mongodb-mongosh \ mongodb-org-mongos-9.0.0 \ mongodb-org-tools-9.0.0 \ mongodb-org-database-tools-extra-9.0.0
You can specify any available version of MongoDB. However, zypper upgrades the packages when a newer version becomes available. To prevent unintended upgrades, pin the packages by running the following command:
sudo zypper addlock \ mongodb-org-9.0.0 \ mongodb-org-database-9.0.0 \ mongodb-org-server-9.0.0 \ mongodb-mongosh \ mongodb-org-mongos-9.0.0 \ mongodb-org-tools-9.0.0 \ mongodb-org-database-tools-extra-9.0.0
Previous versions of MongoDB packages use a different repository location. Refer to the version of the documentation appropriate for your MongoDB version.
Run MongoDB Community Edition
ulimit Considerations
Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.
Note
If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.
Directories
For details on default directories, see Default Data and Log Directory Paths.
Procedure
Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings.
Init System
To run and manage your mongod process, use your operating system's built-in init system. Recent versions of Linux use systemd, which uses the systemctl command, while older versions of Linux use System V init, which uses the service command.
If you are unsure which init system your platform uses, run the following command:
ps --no-headers -o comm 1
Then select the appropriate tab below based on the result:
systemd- select the systemd (systemctl) tab below.init- select the System V Init (service) tab below.
Start MongoDB.
You can start the mongod process by issuing the following command:
sudo systemctl start mongod
If you receive an error similar to the following when starting mongod:
Failed to start mongod.service: Unit mongod.service not found.
Run the following command first:
sudo systemctl daemon-reload
Then run the start command above again.
Verify that MongoDB has started successfully.
You can verify that the mongod process has started successfully by issuing the following command:
sudo systemctl status mongod
You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:
sudo systemctl enable mongod
Stop MongoDB.
As needed, you can stop the mongod process by issuing the following command:
sudo systemctl stop mongod
Restart MongoDB.
You can restart the mongod process by issuing the following command:
sudo systemctl restart mongod
You can follow the state of the process for errors or important messages by watching the output in the /var/log/mongodb/mongod.log file.
Begin using MongoDB.
Start a mongosh session on the same host machine as the mongod. You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with default port 27017.
mongosh
For more information on connecting using mongosh, such as to connect to a mongod instance running on a different host and/or port, see the mongosh documentation.
To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.
Start MongoDB.
You can start the mongod process by issuing the following command:
sudo service mongod start
Verify that MongoDB has started successfully
You can verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading
[initandlisten] waiting for connections on port <port>
where <port> is the port configured in /etc/mongod.conf, 27017 by default.
You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:
sudo chkconfig mongod on
Stop MongoDB.
As needed, you can stop the mongod process by issuing the following command:
sudo service mongod stop
Restart MongoDB.
You can restart the mongod process by issuing the following command:
sudo service mongod restart
You can follow the state of the process for errors or important messages by watching the output in the /var/log/mongodb/mongod.log file.
Begin using MongoDB.
Start a mongosh session on the same host machine as the mongod. You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with default port 27017.
mongosh
For more information on connecting using mongosh, such as to connect to a mongod instance running on a different host and/or port, see the mongosh documentation.
To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.
Additional Information
Localhost Binding by Default
By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.
This value can be configured either:
Warning
Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.
For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.
MongoDB Community Edition Packages
For a complete list of packages, see MongoDB Community Edition Packages.
Install MongoDB Community on SUSE using .tgz Tarball
Overview
Use this tutorial to manually install MongoDB 9.0 Community Edition on SUSE Linux Enterprise Server (SLES) using a downloaded .tgz tarball.
MongoDB Version
This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.
Installation Method
While you can install MongoDB manually using a downloaded .tgz tarball as described in this document, we recommend using the zypper package manager on your system if possible. Using a package manager automatically installs all needed dependencies, provides an example mongod.conf file, and simplifies future upgrade and maintenance tasks.
➤ See Install MongoDB using the zypper Package Manager for instructions.
Considerations
MongoDB Shell, mongosh
When you use the .tgz package to install the server, you need to follow the mongosh installation instructions to download and install mongosh separately.
Platform Support
MongoDB 9.0 Community Edition supports the following 64-bit SUSE Linux Enterprise Server (SLES) releases on x86_64 architecture:
SLES 15
SLES 16
MongoDB only supports the 64-bit versions of these platforms.
See Platform Support for more information.
Production Notes
Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.
Install MongoDB Community Edition
Prerequisites
Use the following command to install the required dependencies for the MongoDB Community .tgz tarball:
sudo zypper install libcurl4 libopenssl1_1
sudo zypper install libcurl4 libopenssl1_1
Procedure
Follow these steps to manually install MongoDB Community Edition from the .tgz.
Download the tarball.
After you have installed the required prerequisite packages, download the MongoDB Community tgz tarball from the following link:
➤
In the Version dropdown, select the version of MongoDB to download.
In the Platform dropdown, select your operating system version and architecture.
In the Package dropdown, select tgz.
Click Download.
Ensure the binaries are in a directory listed in your PATH environment variable.
The MongoDB binaries are in the bin/ directory of the tarball. You can either:
Copy the binaries into a directory listed in your
PATHvariable, such as/usr/local/bin(Update/path/to/the/mongodb-directory/with your installation directory as appropriate)sudo cp /path/to/the/mongodb-directory/bin/* /usr/local/bin/ Create symbolic links to the binaries from a directory listed in your
PATHvariable, such as/usr/local/bin(Update/path/to/the/mongodb-directory/with your installation directory as appropriate):sudo ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/
Install the MongoDB Shell (mongosh).
Install mongosh then use the MongoDB Shell to connect to your deployment.
Download the package for the version of mongosh you need from the MongoDB Download Center and uncompress the package.
Run MongoDB Community Edition
Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings.
Create the data and log directories.
Create a directory where the MongoDB instance stores its data. For example:
sudo mkdir -p /var/lib/mongo
Create a directory where the MongoDB instance stores its log. For example:
sudo mkdir -p /var/log/mongodb
The user that starts the MongoDB process must have read and write permission to these directories. For example, if you intend to run MongoDB as yourself:
sudo chown `whoami` /var/lib/mongo # Or substitute another user sudo chown `whoami` /var/log/mongodb # Or substitute another user
Verify that MongoDB has started successfully.
Verify that MongoDB has started successfully by checking the process output for the following line in the log file /var/log/mongodb/mongod.log:
[initandlisten] waiting for connections on port 27017
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.
Begin using MongoDB.
Start a mongosh session on the same host machine as the mongod. You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with default port 27017.
mongosh
For more information on connecting using mongosh, such as to connect to a mongod instance running on a different host and/or port, see the mongosh documentation.
To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.
Additional Information
Localhost Binding by Default
By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.
This value can be configured either:
Warning
Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.
For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.
Install MongoDB Community Edition on Amazon Linux
Overview
Use this tutorial to install MongoDB 9.0 Community Edition on Amazon Linux using the YUM package manager.
Verify Linux Distribution
You can verify which Linux distribution you are running by running the following command on the command-line:
grep ^NAME /etc/*release
The result should be Amazon Linux or Amazon Linux AMI. If using a different Linux distribution, please see the install instructions for your platform.
MongoDB Version
This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.
Considerations
Platform Support
MongoDB 9.0 Community Edition supports the following 64-bit Amazon Linux release on x86_64 architecture:
- Amazon Linux 2023
MongoDB only supports the 64-bit versions of this platform.
MongoDB 9.0 Community Edition on Amazon Linux also supports the ARM64 architecture on select platforms.
See Platform Support for more information.
Production Notes
Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.
Install MongoDB Community Edition
Follow these steps to install MongoDB Community Edition using the YUM package manager. Select the tab for your version of Amazon Linux:
Configure the repository.
Create a /etc/yum.repos.d/mongodb-org-9.0.repo file so that you can install MongoDB directly using yum:
[mongodb-org-9.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/amazon/2023/mongodb-org/9.0/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://pgp.mongodb.com/server-9.asc
You can also download the .rpm files directly from the MongoDB repository. Downloads are organized by Amazon Linux 2023 version (for example, 2023), then MongoDB version (9.0), then architecture (x86_64 or aarch64).
Install MongoDB Community Server.
To install the latest stable version of MongoDB, run the following command:
sudo yum install -y mongodb-org
To install a specific release of MongoDB, specify each component package individually and append the version number to the package name.
sudo yum install -y \ mongodb-org-9.0.0 \ mongodb-org-database-9.0.0 \ mongodb-org-server-9.0.0 \ mongodb-mongosh \ mongodb-org-mongos-9.0.0 \ mongodb-org-tools-9.0.0 \ mongodb-org-database-tools-extra-9.0.0
Note
yum automatically upgrades packages when newer versions become available. To prevent updates, configure yum to exclude the relevant packages in the /etc/yum.conf file:
exclude=mongodb-org,mongodb-org-database,mongodb-org-server,mongodb-mongosh,mongodb-org-mongos,mongodb-org-tools
Run MongoDB Community Edition
ulimit Considerations
Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.
Note
If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.
Directories
For details on default directories, see Default Data and Log Directory Paths.
Procedure
Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings.
Init System
To run and manage your mongod process, use your operating system's built-in init system. Recent versions of Linux use systemd, which uses the systemctl command, while older versions of Linux use System V init, which uses the service command.
If you are unsure which init system your platform uses, run the following command:
ps --no-headers -o comm 1
Then select the appropriate tab below based on the result:
systemd- select the systemd (systemctl) tab below.init- select the System V Init (service) tab below.
Start MongoDB.
You can start the mongod process by issuing the following command:
sudo systemctl start mongod
If you receive an error similar to the following when starting mongod:
Failed to start mongod.service: Unit mongod.service not found.
Run the following command first:
sudo systemctl daemon-reload
Then run the start command above again.
Verify that MongoDB has started successfully.
You can verify that the mongod process has started successfully by issuing the following command:
sudo systemctl status mongod
You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:
sudo systemctl enable mongod
Stop MongoDB.
As needed, you can stop the mongod process by issuing the following command:
sudo systemctl stop mongod
Restart MongoDB.
You can restart the mongod process by issuing the following command:
sudo systemctl restart mongod
You can follow the state of the process for errors or important messages by watching the output in the /var/log/mongodb/mongod.log file.
Begin using MongoDB.
Start a mongosh session on the same host machine as the mongod. You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with default port 27017.
mongosh
For more information on connecting using mongosh, such as to connect to a mongod instance running on a different host and/or port, see the mongosh documentation.
To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.
Start MongoDB.
You can start the mongod process by issuing the following command:
sudo service mongod start
Verify that MongoDB has started successfully
You can verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading
[initandlisten] waiting for connections on port <port>
where <port> is the port configured in /etc/mongod.conf, 27017 by default.
You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:
sudo chkconfig mongod on
Stop MongoDB.
As needed, you can stop the mongod process by issuing the following command:
sudo service mongod stop
Restart MongoDB.
You can restart the mongod process by issuing the following command:
sudo service mongod restart
You can follow the state of the process for errors or important messages by watching the output in the /var/log/mongodb/mongod.log file.
Begin using MongoDB.
Start a mongosh session on the same host machine as the mongod. You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with default port 27017.
mongosh
For more information on connecting using mongosh, such as to connect to a mongod instance running on a different host and/or port, see the mongosh documentation.
To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.
Additional Information
Localhost Binding by Default
By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.
This value can be configured either:
Warning
Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.
For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.
MongoDB Community Edition Packages
For a complete list of packages, see MongoDB Community Edition Packages.
Install MongoDB Community on Amazon Linux using .tgz Tarball
Overview
Use this tutorial to manually install MongoDB 9.0 Community Edition on Amazon Linux using a downloaded .tgz tarball.
Verify Linux Distribution
You can verify which Linux distribution you are running by running the following command on the command-line:
grep ^NAME /etc/*release
The result should be Amazon Linux or Amazon Linux AMI. If using a different Linux distribution, please see the install instructions for your platform.
MongoDB Version
This tutorial installs MongoDB 9.0 Community Edition. To install a different version of MongoDB Community, use the version drop-down menu in the upper-left corner of this page to select the documentation for that version.
Installation Method
While you can install MongoDB manually using a downloaded .tgz tarball as described in this document, we recommend using the yum package manager on your system if possible. Using a package manager automatically installs all needed dependencies, provides an example mongod.conf file, and simplifies future upgrade and maintenance tasks.
➤ See Install MongoDB using the yum Package Manager for instructions.
Considerations
MongoDB Shell, mongosh
When you use the .tgz package to install the server, you need to follow the mongosh installation instructions to download and install mongosh separately.
Platform Support
MongoDB 9.0 Community Edition supports the following 64-bit Amazon Linux release on x86_64 architecture:
- Amazon Linux 2023
MongoDB only supports the 64-bit versions of this platform.
MongoDB 9.0 Community Edition on Amazon Linux also supports the ARM64 architecture on select platforms.
See Platform Support for more information.
Production Notes
Before deploying MongoDB in a production environment, see the Production Notes for Self-Managed Deployments document for performance considerations and configuration recommendations.
Install MongoDB Community Edition
Prerequisites
Use the following command to install the required dependencies for the MongoDB Community .tgz tarball:
sudo yum install libcurl openssl xz-libs
Procedure
Follow these steps to manually install MongoDB Community Edition from the .tgz.
Download the tarball.
After you have installed the required prerequisite packages, download the MongoDB Community tgz tarball from the following link:
➤
In the Version dropdown, select the version of MongoDB to download.
In the Platform dropdown, select your operating system version and architecture.
In the Package dropdown, select tgz.
Click Download.
Extract the files from the downloaded archive.
Using an archive manager program or the tar command, extract the files. For example, to extract from the terminal shell, you can use the following tar command:
Tip
If you downloaded a different MongoDB 9.0 point release, be sure to modify the command to reflect the correct .tgz file name.
tar -zxvf mongodb-linux-x86_64-*-9.0.0.tgz
Optional. Ensure the binaries are in a directory listed in your PATH environment variable.
The MongoDB binaries are in the <mongodb-install-directory>/bin directory. To avoid having to specify the path to the MongoDB binaries, add the contents of the <mongodb-install-directory>/bin/ directory to a directory in the $PATH such as /usr/bin/. For example, you can either:
Copy the binaries into
/usr/bin/.sudo cp <mongodb-install-directory>/bin/* /usr/bin/ -OR-
Create symbolic links to each of these binaries to
/usr/bin/:sudo ln -s /full/path/to/<mongodb-install-directory>/bin/* /usr/bin/ Replace
/full/path/towith the full path to the extracted directory contents.
Install the MongoDB Shell (mongosh).
Install mongosh then use the MongoDB Shell to connect to your deployment.
Download the package for the version of mongosh you need from the MongoDB Download Center and uncompress the package.
Run MongoDB Community Edition
ulimit Considerations
Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted. See UNIX ulimit Settings for Self-Managed Deployments for the recommended settings for your platform.
Note
If the ulimit value for number of open files is under 64000, MongoDB generates a startup warning.
Directories
By default, a MongoDB instance stores:
its data files in
/var/lib/mongoits log files in
/var/log/mongodb
If you installed using the package manager, these default directories are created during installation.
If you installed manually by downloading the tarballs, create the directories using mkdir -p <directory> or sudo mkdir -p <directory> depending on the user that will run MongoDB. See your linux man pages for information on mkdir and sudo.
By default, MongoDB runs using the mongod user account. If you change the user that runs the MongoDB process, you must also modify the permission to the /var/lib/mongo and /var/log/mongodb directories to give this user access to these directories.
To specify a different log file directory and data file directory, edit the systemLog.path and storage.dbPath settings in the /etc/mongod.conf. Ensure that the user running MongoDB has access to these directories.
Procedure
Follow these steps to run MongoDB Community Edition. These instructions assume that you are using the default settings.
Create the data and log directories.
Create a directory where the MongoDB instance stores its data. For example:
sudo mkdir -p /var/lib/mongo
Create a directory where the MongoDB instance stores its log. For example:
sudo mkdir -p /var/log/mongodb
The user that starts the MongoDB process must have read and write permission to these directories. For example, if you intend to run MongoDB as yourself:
sudo chown `whoami` /var/lib/mongo # Or substitute another user sudo chown `whoami` /var/log/mongodb # Or substitute another user
Verify that MongoDB has started successfully.
Verify that MongoDB has started successfully by checking the process output for the following line in the log file /var/log/mongodb/mongod.log:
[initandlisten] waiting for connections on port 27017
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.
Begin using MongoDB.
Start a mongosh session on the same host machine as the mongod. You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with default port 27017.
mongosh
For more information on connecting using mongosh, such as to connect to a mongod instance running on a different host and/or port, see the mongosh documentation.
To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.
Additional Information
Localhost Binding by Default
By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.
This value can be configured either:
Warning
Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. At minimum, consider enabling authentication and hardening network infrastructure.
For more information on configuring bindIp, see IP Binding in Self-Managed Deployments.
Next Steps
After you install MongoDB Community Edition, you can:
Get started: Work through an introductory tutorial. To learn more, see Getting Started with MongoDB.
Deploy a replica set: Set up replication for high availability. To learn how, see Deploy a Self-Managed Replica Set.
Set up access control: Secure your deployment with authentication. To learn how, see Enable Access Control on Self-Managed Deployments.
Review the security checklist: Confirm your deployment follows security best practices. To learn more, see Security Checklist for Self-Managed Deployments.
Upgrade Community Edition to Enterprise Edition Tutorials
Important
Do not use these instructions to upgrade to another release version.
For general guidance on MongoDB version numbering, release types, and upgrade paths, see MongoDB Versions and Upgrade Paths.