Install the MongoDB CLI
You can use the MongoDB Command Line Interface (mongocli
) to deploy and manage MongoDB clusters in
Atlas, Cloud Manager, and Ops Manager. For operating system and MongoDB
service version requirements, see Compatibility.
To install the MongoDB CLI, choose one of the following methods:
Install with a package manager like Homebrew, Yum, or Apt.
Download and extract the binary.
Clone the GitHub repository and install the MongoDB CLI with Go.
Prerequisites
To install the MongoDB CLI using Homebrew, you must:
Use a MacOS or Linux operating system.
Install Homebrew.
Procedure
Configure yum
for your edition of MongoDB.
Create a /etc/yum.repos.d/mongodb-org-5.0.repo
file so that you can install MongoDB CLI directly using yum
.
[mongodb-org-5.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/5.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc
Create a
/etc/yum.repos.d/mongodb-enterprise-5.0.repo
file
so that you can install MongoDB CLI directly using
yum
:
[mongodb-enterprise-5.0] name=MongoDB Repository baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/5.0/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc
Import the public key used by apt
.
From a terminal, issue the following command to import the MongoDB public GPG Key from https://www.mongodb.org/static/pgp/server-5.0.asc.
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
A successful command returns an OK
.
Create a list file for your edition of MongoDB.
Create the list file /etc/apt/sources.list.d/mongodb-org-5.0.list
for your version of Ubuntu.
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
Create a /etc/apt/sources.list.d/mongodb-enterprise.list
file for MongoDB.
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-enterprise/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-enterprise/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list
Install the MongoDB CLI.
Download and extract the correct binary for your operating system:
Operating SystemDownloadWindowsMacOSUbuntu/DebianRHEL/CentOS/SLES/AMZLinuxNote
Replace or remove any existing MongoDB CLI binaries to prevent conflicts between versions.
Run the executable file.
Tip
You can run the binary from any directory. Because you don't need to install the MongoDB CLI into a global location, you can use it on shared hosts and other systems where you don't have a privileged account.
Add mongocli
to your PATH
.
To run mongocli
commands from anywhere in your system, you must
either:
Add the location of the executable to your
PATH
orMove the executable to a directory in your
PATH
.
You can accomplish this in several ways, depending on your personal settings and environment. Consult the documentation for your shell and operating system for more examples.
Example
In the following example, the user downloads and installs
the MongoDB CLI by cloning the GitHub repository. The mongocli
executable file saves to the location specified by your
$GOPATH environment variable.
The default location is $HOME/go
on Unix systems and
%USERPROFILE%\go
on Windows.
The user then adds this directory to their PATH
:
export PATH="$HOME/go:$PATH"
Example
In the following example, the user downloads and extracts a
binary for the MongoDB CLI to the /mcli_1.18.0-macOS_x86_64
directory.
The user then moves the executable file to a directory already in
their PATH
:
cd mcli_1.18.0-macOS_x86_64 mv mongocli /usr/local/bin
Add mongocli
to your PATH
.
To run mongocli
commands from anywhere in your system, you must
either:
Add the location of the executable to your
PATH
orMove the executable to a directory in your
PATH
.
You can accomplish this in several ways, depending on your personal settings and environment. Consult the documentation for your shell and operating system for more examples.
Example
In the following example, the user downloads and installs
the MongoDB CLI by cloning the GitHub repository. The mongocli
executable file saves to the location specified by your
$GOPATH environment variable.
The default location is $HOME/go
on Unix systems and
%USERPROFILE%\go
on Windows.
The user then adds this directory to their PATH
:
export PATH="$HOME/go:$PATH"
Example
In the following example, the user downloads and extracts a
binary for the MongoDB CLI to the /mcli_1.18.0-macOS_x86_64
directory.
The user then moves the executable file to a directory already in
their PATH
:
cd mcli_1.18.0-macOS_x86_64 mv mongocli /usr/local/bin
Next Steps
Configure the MongoDB CLI for your environment.