Docs Menu
Docs Home
/ /
MongoDB CLI

Install or Update the MongoDB CLI

On this page

  • Install the MongoDB CLI
  • Update the MongoDB CLI
  • Next Steps

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 verify packages before installation, see Verify the Integrity of MongoDB CLI Packages.

To install the MongoDB CLI, choose one of the following methods:

  1. Install with a package manager like Homebrew, Yum, or Apt.

  2. Download and extract the binary.

  3. Clone the GitHub repository and install the MongoDB CLI with Go.

To install the MongoDB CLI using Homebrew, you must:

  1. Use a MacOS or Linux operating system.

  2. Install Homebrew.

To install the MongoDB CLI using Apt, you must install gnupg:

sudo apt-get install gnupg
1

Invoke the following brew commands:

brew install mongocli
2

To verify your mongocli installation, run the help command:

mongocli help

The command returns the available commands and options for the MongoDB CLI.

1

Create a /etc/yum.repos.d/mongodb-org-6.0.repo file so that you can install MongoDB CLI directly using yum.

[mongodb-org-6.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/6.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc
[mongodb-org-6.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2/mongodb-org/6.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc

Create a /etc/yum.repos.d/mongodb-enterprise-6.0.repo file so that you can install MongoDB CLI directly using yum:

[mongodb-enterprise-6.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/6.0/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc
[mongodb-enterprise-6.0]
name=MongoDB Enterprise Repository
baseurl=https://repo.mongodb.com/yum/amazon/2/mongodb-enterprise/6.0/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc
2

Invoke the following yum command:

sudo yum install -y mongocli
3

To verify your mongocli installation, run the help command:

mongocli help

The command returns the available commands and options for the MongoDB CLI.

1

From a terminal, issue the following command to import the MongoDB public GPG Key from https://www.mongodb.org/static/pgp/server-6.0.asc.

wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -

A successful command returns an OK.

2

Create the list file /etc/apt/sources.list.d/mongodb-org-6.0.list for your version of Ubuntu.

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
echo "deb http://repo.mongodb.org/apt/debian bullseye/mongodb-org/6.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/6.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

Create a /etc/apt/sources.list.d/mongodb-enterprise.list file for MongoDB.

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.com/apt/ubuntu jammy/mongodb-enterprise/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.com/apt/ubuntu focal/mongodb-enterprise/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.com/apt/ubuntu bionic/mongodb-enterprise/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list
echo "deb http://repo.mongodb.com/apt/debian bullseye/mongodb-enterprise/6.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list
echo "deb http://repo.mongodb.com/apt/debian buster/mongodb-enterprise/6.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list
3

Invoke the following command:

sudo apt-get update
4

Invoke the following command:

sudo apt-get install -y mongocli
5

To verify your mongocli installation, run the help command:

mongocli help

The command returns the available commands and options for the MongoDB CLI.

1
  1. Download and extract the correct binary for your operating system:

    Operating System
    Download
    Windows
    MacOS
    Ubuntu/Debian
    RHEL/CentOS/SLES/AMZ
    Linux

    Note

    Replace or remove any existing MongoDB CLI binaries to prevent conflicts between versions.

  2. 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.

2

To run mongocli commands from anywhere in your system, you must either:

  1. Add the location of the executable to your PATH or

  2. Move 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_2.0.1-macOS_x86_64 directory.

The user then moves the executable file to a directory already in their PATH:

cd mcli_2.0.1-macOS_x86_64
mv mongocli /usr/local/bin
3

To verify your mongocli installation, run the help command:

mongocli help

The command returns the available commands and options for the MongoDB CLI.

To update the MongoDB CLI, follow the procedure for the method with which you installed the MongoDB CLI:

1

Invoke the following brew commands:

brew update
brew upgrade mongocli
2

To verify your mongocli update, run the --version command:

mongocli --version

The command returns your MongoDB CLI version.

1

Invoke the following yum command:

yum update mongocli
2

To verify your mongocli update, run the --version command:

mongocli --version

The command returns your MongoDB CLI version.

1

Invoke the following command:

sudo apt-get install --only-upgrade mongocli
2

To verify your mongocli update, run the --version command:

mongocli --version

The command returns your MongoDB CLI version.

1
  1. Remove any existing MongoDB CLI binaries to prevent conflicts between versions.

  2. Download and extract the correct binary for your operating system:

    Operating System
    Download
    Windows

    .zip, .msi

    The .msi download for Windows replaces old installations of the MongoDB CLI, so you don't need to remove existing binaries first.

    MacOS
    Ubuntu/Debian
    RHEL/CentOS/SLES/AMZ
    Linux
  3. Run the executable file.

2

To verify your mongocli update, run the --version command:

mongocli --version

The command returns your MongoDB CLI version.