Navigation

    Install mongosh

    Beta

    The MongoDB Shell (mongosh) is currently available as a Beta release. The product, its features, and the corresponding documentation may change during the Beta stage.

    Prerequisites

    To use the MongoDB Shell, you must have a MongoDB deployment to connect to.

    Procedure

    Install with Homebrew

    important

    To view the complete list of system requirements for Homebrew, see the Homebrew Website.

    The Homebrew package manager is the recommended installation method for mongosh on macOS. To learn how to manually install mongosh from an archive instead, see Install from Tarball.

    To install mongosh with Homebrew:

    1

    Install Homebrew.

    Refer to the Homebrew website for the steps to install Homebrew on macOS.

    2

    Tap the MongoDB Homebrew Tap.

    Issue the following command from the terminal to tap the official MongoDB Homebrew Tap:

    brew tap mongodb/brew
    3

    Install the mongosh package.

    Issue the following command from the terminal to install the mongosh package:

    brew install mongosh

    Install from Tarball

    To manually install mongosh using a downloaded .tgz tarball:

    1

    Open the MongoDB Download Center.

    2

    Open the MongoDB Shell Download Page.

    Click Tools, then select Shell.

    3

    Download the installation archive for your operating system.

    4

    Extract the files from the downloaded archive.

    tar -zxvf path/to/archive

    If your web browser automatically extracts the archive as part of the download or you extract the archive without the tar command, you may need to run the following command to make mongosh executable:

    chmod +x /path/to/mongosh
    5

    Add the mongosh binary to your PATH environment variable.

    You can either:

    • Copy the mongosh binary into a directory listed in your PATH variable, such as /usr/local/bin (Update /path/to/mongosh with your installation directory as appropriate)

      sudo cp /path/to/mongosh /usr/local/bin/
    • Create a symbolic link to the mongosh binary from a directory listed in your PATH variable, such as /usr/local/bin (Update /path/to/mongosh with your installation directory as appropriate):

      sudo ln -s  /path/to/mongosh /usr/local/bin/
    6

    Allow macOS to Run mongosh.

    macOS may prevent mongosh from running after installation. If you receive a security error when starting mongosh indicating that the developer could not be identified or verified, perform the following actions:

    1. Open System Preferences.
    2. Select the Security and Privacy pane.
    3. Under the General tab, click the button to the right of the message about mongosh, labelled either Open Anyway or Allow Anyway depending on your version of macOS.
    1

    Open the MongoDB Download Center.

    2

    Open the MongoDB Shell Download Page.

    Click Tools, then select Shell.

    3

    Download the installation archive for your operating system.

    4

    Extract the files from the downloaded archive.

    5

    Add the MongoDB Shell binary to your PATH environment variable.

    Ensure that the extracted MongoDB Shell binary is in the desired location in your filesystem, then add that location to your PATH environment variable.

    To add the MongoDB Shell binary's location to your PATH environment variable:

    1. Open the Control Panel.
    2. In the System and Security category, click System.
    3. Click Advanced system settings. The System Properties modal displays.
    4. Click Environment Variables.
    5. In the System variables section, select Path and click Edit. The Edit environment variable modal displays.
    6. Click New and add the filepath to your mongosh binary.
    7. Click OK to confirm your changes. On each other modal, click OK to confirm your changes.

    To confirm that your PATH environment variable is correctly configured to find mongosh, open a command prompt and enter the mongosh --help command. If your PATH is configured correctly, a list of valid commands displays.

    1

    Open the MongoDB Download Center.

    2

    Open the MongoDB Shell Download Page.

    Click Tools, then select Shell.

    3

    Download the installation archive for your operating system.

    4

    Extract the files from the downloaded archive.

    tar -zxvf path/to/archive

    If your web browser automatically extracts the archive as part of the download or you extract the archive without the tar command, you may need to run the following command to make mongosh executable:

    chmod +x /path/to/mongosh
    5

    Add the mongosh binary to your PATH environment variable.

    You can either:

    • Copy the mongosh binary into a directory listed in your PATH variable, such as /usr/local/bin (Update /path/to/mongosh with your installation directory as appropriate)

      sudo cp /path/to/mongosh /usr/local/bin/
    • Create a symbolic link to the mongosh binary from a directory listed in your PATH variable, such as /usr/local/bin (Update /path/to/mongosh with your installation directory as appropriate):

      sudo ln -s  /path/to/mongosh /usr/local/bin/

    Next Steps

    Once you successfully install mongosh, learn how to connect to your MongoDB deployment.