Install mongosh (original) (raw)

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

You can use the MongoDB Shell to connect to MongoDB version 4.2 or greater.

You can install MongoDB Shell 2.0.0 on these operating systems:

Operating System Supported Versions
macOS 11+ (x64 and ARM64)
Microsoft Windows Microsoft Windows Server 2016+Microsoft Windows 10+
Linux Red Hat Enterprise Linux (RHEL) 8+ (x64, ARM64, ppc64le, and s390x)Ubuntu 20.04+ (x64 and ARM64)Amazon Linux 2023 (x64 and ARM64)Amazon Linux 2 (x64 and ARM64)Debian 11+SLES 15Oracle Linux 8+ running the Red Hat Compatible Kernel (RHCK). MongoDB Shell does not support the Unbreakable Enterprise Kernel (UEK).

Starting in mongosh 2.0.0:

Select the appropriate tab for your operating system:

Note

On Windows, mongosh preferences and configuration options are stored in the %APPDATA%/mongodb/mongosh directory.

Open a cmd terminal and run the following command from the directory that has the mongosh .zip archive:


tar -xf mongosh-2.4.0-win32-x64.zip

The extracted archive has a bin folder that contains two files,mongosh.exe and mongosh_crypt_v1.dll.

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

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

  1. Open the Control Panel.
  2. In the System and Security category, clickSystem.
  3. Click Advanced system settings. The System Properties modal displays.
  4. Click Environment Variables.
  5. In the System variables section, select Path and clickEdit. The Edit environment variable modal displays.
  6. Click New and add the filepath to your mongoshbinary.
  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 themongosh --help command. If your PATH is configured correctly, a list of valid commands displays.

Important

To view the complete list of system requirements for Homebrew, see theHomebrew 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, seeInstall from .zip File.

mongosh installed with Homebrew does not supportautomatic client-side field level encryption.

To install mongosh with Homebrew:

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

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

To manually install mongosh using a downloaded .zipfile:

Download the appropriate version of mongosh for your operating system. MongoDB provides versions of mongosh for Intel and ARM architectures.

Go to the directory that contains the mongosh .zip archive, then unpack the .zip file.

If your computer is Intel based, run:


unzip mongosh-2.4.0-darwin-x64.zip

If your computer is ARM based (M1 or M2), run:


unzip mongosh-2.4.0-darwin-arm64.zip

The extracted archive has a bin folder that contains two files,mongosh and mongosh_crypt_v1.dylib.

If your web browser automatically extracts the archive as part of the download, or if you extract the archive without using the unzipcommand, you may need to make the binary executable.

To make the binary executable, run the following command in the directory where you extracted the archive:

You can either:

sudo cp mongosh /usr/local/bin/  
sudo cp mongosh_crypt_v1.so /usr/local/lib/  
sudo ln -s $(pwd)/bin/* /usr/local/bin/  

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 Anywayor Allow Anyway depending on your version of macOS.

Select the appropriate tab based on your Linux distribution and desired package from the tabs below:

mongosh is available as a PPA for the following platforms:

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


wget -qO- https://www.mongodb.org/static/pgp/server-8.0.asc | sudo tee /etc/apt/trusted.gpg.d/server-8.0.asc

The previous command writes the GPG key to your system's/etc/apt/trusted.gpg.d folder and prints the key to your terminal. You do not need to copy or save the key that is printed to the terminal.

If you receive an error indicating that gnupg is not installed, perform the following steps:

  1. Install gnupg and its required libraries using the following command:
sudo apt-get install gnupg  
  1. Retry importing the key:
wget -qO- https://www.mongodb.org/static/pgp/server-8.0.asc | sudo tee /etc/apt/trusted.gpg.d/server-8.0.asc  

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

Click on the appropriate tab for your version of Ubuntu. If you are unsure of what Ubuntu version the host is running, open a terminal or shell on the host and run lsb_release -dc.

The following instruction is for Ubuntu 24.04 (Noble Numbat). For other Ubuntu releases, click the appropriate tab.

Create the/etc/apt/sources.list.d/mongodb-org-8.0.listfile for Ubuntu 24.04 (Noble Numbat):


echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list

The following instruction is for Ubuntu 22.04 (Jammy). For other Ubuntu releases, click the appropriate tab.

Create the/etc/apt/sources.list.d/mongodb-org-8.0.listfile for Ubuntu 22.04 (Jammy):


echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list

The following instruction is for Ubuntu 20.04 (Focal). For other Ubuntu releases, click the appropriate tab.

Create the/etc/apt/sources.list.d/mongodb-org-8.0.listfile for Ubuntu 20.04 (Focal):


echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list

The following instruction is for Ubuntu 18.04 (Bionic). For other Ubuntu releases, click the appropriate tab.

Create the/etc/apt/sources.list.d/mongodb-org-8.0.listfile for Ubuntu 18.04 (Bionic):


echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list

Issue the following command to reload the local package database:

mongosh supports OpenSSL. You can also configure mongosh to use your system's OpenSSL installation.

To install the latest stable version of mongosh with the included OpenSSL libraries:


sudo apt-get install -y mongodb-mongosh

To install mongosh with your OpenSSL 1.1 libraries:


sudo apt-get install -y mongodb-mongosh-shared-openssl11

To install mongosh with your OpenSSL 3.0 libraries:


sudo apt-get install -y mongodb-mongosh-shared-openssl3

To confirm that mongosh installed successfully, run the following command:

Your terminal should respond with the version of mongosh you have installed.

mongosh is available as yum package for the following platforms:

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

There are .rpm distributions for RHEL and Amazon Linux.


[mongodb-org-8.0]

name=MongoDB Repository

baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/8.0/$basearch/

gpgcheck=1

enabled=1

gpgkey=https://www.mongodb.org/static/pgp/server-8.0.asc

You can also download the .rpm files directly from theMongoDB repository. Downloads are organized in the following order:

  1. Red Hat or CentOS version (for example, 8)
  2. MongoDB edition (for example, mongodb-enterprise)
  3. MongoDB release version(for example, 8.0)
  4. Architecture (for example, x86_64)

[mongodb-org-8.0]

name=MongoDB Repository

baseurl=https://repo.mongodb.org/yum/amazon/2023/mongodb-org/8.0/$basearch/

gpgcheck=1

enabled=1

gpgkey=https://www.mongodb.org/static/pgp/server-8.0.asc

Note

If your system uses Amazon Linux 2, replace 2023 with2 in the baseurl.

You can also download the .rpm files directly from theMongoDB repository. Downloads are organized in the following order:

  1. Amazon Linux version (for example, 2023)
  2. MongoDB release version(for example, 8.0)
  3. Architecture (for example, x86_64)

mongosh supports OpenSSL. You can also configure mongosh to use your system's OpenSSL installation.

To install the latest stable version of mongosh with the included OpenSSL libraries:


sudo yum install -y mongodb-mongosh

To install mongosh with your OpenSSL 1.1 libraries:


sudo yum install -y mongodb-mongosh-shared-openssl11

To install mongosh with your OpenSSL 3.0 libraries:


sudo yum install -y mongodb-mongosh-shared-openssl3

Download the appropriate version of mongosh for your operating system. MongoDB also provides versions of mongosh that use your system's OpenSSL installation.

See the MongoDB Download Center.

Go to the directory that contains the .tgz archive, then unpack the archive.

The name of the .tgz package varies depending on the version you downloaded. Replace the .tgz package name in the following command with the name of the package you downloaded and run the command.


tar -zxvf mongosh-2.4.0-linux-x64.tgz

The extracted archive has a bin folder that contains two files,mongosh and mongosh_crypt_v1.so.

If your web browser automatically extracts the archive as part of the download, or if you extract the archive without using the tarcommand, you may need to make the binary executable.

To make the binary executable, run the following command in the directory where you extracted the archive:

You can either:

sudo cp mongosh /usr/local/bin/  
sudo cp mongosh_crypt_v1.so /usr/local/lib/  
sudo ln -s $(pwd)/bin/* /usr/local/bin/  

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

MongoDB provides a programmatically accessible list of mongosh downloads that can be accessed through your application.