Navigation

Install the MongoDB CLI

On this page

You can use the MongoDB Command Line Interface (mongocli) to deploy and manage MongoDB clusters in Atlas, Cloud Manager, and Ops Manager.

Ops Manager Compatibility

MongoDB CLI is compatible with Ops Manager v4.2.0 and later.

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

  1. Install with Homebrew (MacOS and Linux only).
  2. Download and extract the binary.
  3. Clone the GitHub repository and install the MongoDB CLI with Go.

Prerequisites

To install the MongoDB CLI using Homebrew, you must:

  1. Use a MacOS or Linux operating system.
  2. Install Homebrew.

Prerequisites

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

  1. Git.
  2. Go v1.14 or newer.

Procedure

1

Install the MongoDB CLI

Invoke the following brew commands:

brew tap mongodb/brew
brew install mongocli
2

Verify your installation.

To verify your mongocli installation, run the help command:

mongocli help

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

1

Install the MongoDB CLI.

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

    Operating System Download
    Windows .zip
    MacOS .tar.gz
    Ubuntu/Debian .deb
    RHEL/CentOS/SLES/AMZ .rpm
    Linux .tar.gz

    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

Add mongocli to your PATH.

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.1.0-macOS_x86_64 directory.

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

cd mcli_1.1.0-macOS_x86_64
mv mongocli /usr/local/bin
3

Verify your installation.

To verify your mongocli installation, run the help command:

mongocli help

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

1

Install the MongoDB CLI.

  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

Add mongocli to your PATH.

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.1.0-macOS_x86_64 directory.

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

cd mcli_1.1.0-macOS_x86_64
mv mongocli /usr/local/bin
3

Verify your installation.

To verify your mongocli installation, run the help command:

mongocli help

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

Next Steps

Configure the MongoDB CLI for your environment.