Docs Menu
Docs Home
/ /
MongoDB Command Line Interface

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

To install the MongoDB CLI, you must install the following tools:

  1. Git.

  2. Go v1.17 or newer.

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

2

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.com/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.com/apt/ubuntu bionic/mongodb-enterprise/5.0 multiverse" | 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_1.21.0-macOS_x86_64 directory.

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

cd mcli_1.21.0-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.

1
  1. Clone the repository:

    git clone https://github.com/mongodb/mongocli.git
  2. Change directories to your local repostiory:

    cd mongocli
  3. Install MongoDB CLI using Go.

    make install
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_1.21.0-macOS_x86_64 directory.

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

cd mcli_1.21.0-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

    Note

    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.

1
  1. Change directories to your local mongocli repostiory:

    cd mongocli
  1. Update your local repository with the latest changes from MongoDB:

    git pull
  2. Reinstall MongoDB CLI using Go.

    make install
2

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

mongocli --version

The command returns your MongoDB CLI version.