Install 安装mongosh
On this page本页内容
Prerequisites先决条件
To use the MongoDB Shell, you must have a MongoDB deployment to connect to.要使用MongoDB Shell,您必须有一个MongoDB部署来连接。
For a free cloud-hosted deployment, you can use MongoDB Atlas.对于免费的云托管部署,您可以使用MongoDB Atlas.。
To learn how to run a local MongoDB deployment, see Install MongoDB.要了解如何运行本地MongoDB部署,请参阅安装MongoDB。
Supported MongoDB Versions支持的MongoDB版本
You can use the MongoDB Shell to connect to MongoDB version 4.2 or greater.您可以使用MongoDB Shell连接到MongoDB 4.2或更高版本。
Procedure过程
Select the appropriate tab for your operating system:为您的操作系统选择适当的选项卡:
On Windows, 在Windows上,mongosh preferences and configuration options are stored in the %APPDATA%/mongodb/mongosh directory.mongosh首选项和配置选项存储在%APPDATA%/mongodb/mongosh目录中。
Install from MSI从MSI安装
Open the MongoDB Shell download page.打开MongoDB Shell下载页面。
Open the MongoDB Download Center.打开MongoDB下载中心。
Install from .zip File从.zip文件安装
.zip FileOpen the MongoDB Shell download page.打开MongoDB Shell下载页面。
Open the MongoDB Download Center.打开MongoDB下载中心。
Download the mongosh installation archive for your operating system.下载适用于您的操作系统的mongosh安装档案。
mongosh installation archive for your operating system.Download 从MongoDB下载中心下载mongosh from the MongoDB Download Center.mongosh。
Extract the files from the downloaded archive.从下载的存档中提取文件。
Open a 打开cmd终端,并从具有cmd terminal and run the following command from the directory that has the mongosh .zip archive:mongosh .zip存档的目录中运行以下命令:
tar -xf mongosh-1.10.1-win32-x64.zip
The extracted archive has a 提取的归档文件有一个bin folder that contains two files, mongosh.exe and mongosh_crypt_v1.dll.bin文件夹,其中包含两个文件,mongosh.exe和mongosh_crypt_v1.dll。
Add the mongosh binary to your PATH environment variable.将mongosh二进制文件添加到PATH环境变量中。
mongosh 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 确保提取的MongoDB Shell二进制文件位于文件系统中所需的位置,然后将该位置添加到PATH environment variable.PATH环境变量中。
To add the MongoDB Shell binary's location to your 要将MongoDB Shell二进制文件的位置添加到PATH environment variable:PATH环境变量中,请执行以下操作:
Open the Control Panel.打开“控制面板”。In the System and Security category, click System.在“系统和安全”类别中,单击“系统”。Click Advanced system settings.单击“高级系统设置”。The System Properties modal displays.将显示“系统属性”模式。Click Environment Variables.单击“环境变量”。In the System variables section, select在“系统变量”部分,选择“路径”,然后单击“编辑”。Pathand click Edit.The Edit environment variable modal displays.将显示“编辑环境变量”模态。Click New and add the filepath to your单击“新建”并将文件路径添加到您的mongoshbinary.mongosh二进制文件中。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. PATH环境变量已正确配置为查找mongosh,请打开命令提示符并输入mongosh --help命令。If your 如果PATH is configured correctly, a list of valid commands displays.PATH配置正确,将显示一个有效命令列表。
Install with Homebrew使用Homebrew安装
To view the complete list of system requirements for Homebrew, see the Homebrew Website.要查看Homebrew系统要求的完整列表,请参阅Homebrew网站。
The Homebrew package manager is the recommended installation method for Homebrew软件包管理器是mongosh on macOS. mongosh在macOS上的推荐安装方法。To learn how to manually install 要了解如何从存档手动安装mongosh from an archive instead, see Install from .zip File.mongosh,请参阅从.zip文件安装。
Considerations注意事项
与Homebrew一起安装的mongosh installed with Homebrew does not support automatic client-side field level encryption.mongosh不支持自动客户端字段级加密。
Procedure过程
To install 要使用Homebrew安装mongosh with Homebrew:mongosh:
Install from .zip File从.zip文件安装
.zip FileTo manually install 要使用下载的mongosh using a downloaded .zip file:.zip文件手动安装mongosh,请执行以下操作:
Open the MongoDB Shell download page.打开MongoDB Shell下载页面。
Open the MongoDB Download Center.打开MongoDB下载中心。
Download the mongosh installation archive for your operating system.下载适用于您的操作系统的mongosh安装档案。
mongosh installation archive for your operating system.Download the appropriate version of 下载适用于您的操作系统的mongosh for your operating system. mongosh的适当版本。MongoDB provides versions of MongoDB为Intel和ARM架构提供了mongosh for Intel and ARM architectures.mongosh版本。
See the MongoDB Download Center.请参阅MongoDB下载中心。
Extract the files from the downloaded archive.从下载的存档中提取文件。
Go to the directory that contains the 转到包含mongosh .zip archive, then unpack the .zip file.mongosh .zip归档文件的目录,然后解压缩.zip文件。
If your computer is Intel based, run:如果您的计算机是基于英特尔的,请运行:
unzip mongosh-1.10.1-darwin-x64.zip
If your computer is ARM based (M1 or M2), run:如果您的计算机是基于ARM的(M1或M2),请运行:
unzip mongosh-1.10.1-darwin-arm64.zip
The extracted archive has a 提取的归档文件有一个bin folder that contains two files, mongosh and mongosh_crypt_v1.dylib.bin文件夹,其中包含两个文件mongosh和mongosh_crypt_v1dylib。
If your web browser automatically extracts the archive as part of the download, or if you extract the archive without using the 如果您的web浏览器在下载过程中自动提取存档,或者如果您在不使用unzip command, you may need to make the binary executable.unzip命令的情况下提取存档,则可能需要使二进制文件可执行。
To make the binary executable, run the following command in the directory where you extracted the archive:要使二进制文件可执行,请在提取存档的目录中运行以下命令:
chmod +x bin/mongosh
Add the downloaded binaries to your PATH environment variable.
You can either:
- Copy the
mongoshbinary into a directory listed in yourPATHvariable, such as/usr/local/bin. Run the following commands from the directory where you extracted the download file:sudo cp mongosh /usr/local/bin/
sudo cp mongosh_crypt_v1.so /usr/local/lib/ - Create symbolic links to the
MongoDB Shell. Switch to the directory where you extracted the files from the.tgzarchive. Run the following command to create links to a directory already in yourPATHsuch as/usr/local/bin.sudo ln -s $(pwd)/bin/* /usr/local/bin/
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:
- Open System Preferences.
- Select the Security and Privacy pane.
- 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.
Select the appropriate tab based on your Linux distribution and desired package from the tabs below:
- To install the
.debpackage on Ubuntu 22.04 (Jammy), Ubuntu 20.04 (Focal), Ubuntu 18.04 (Bionic), or Debian, click the.debtab. - To install the
.rpmpackage on RHEL or Amazon Linux 2, click the.rpmtab. - To install the
.tgztarball, click the.tgztab.
Supported Platforms支持的平台
mongosh is available as a PPA for the following platforms:
- Ubuntu 22.04 (Jammy)
- Ubuntu 20.04 (Focal)
- Ubuntu 18.04 (Bionic)
Procedure
Import the public key used by the package management system.导入包管理系统使用的公钥。
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 tee /etc/apt/trusted.gpg.d/server-6.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:
- Install
gnupgand its required libraries using the following command:sudo apt-get install gnupg
- Retry importing the key:
wget -qO- https://www.mongodb.org/static/pgp/server-6.0.asc | sudo tee /etc/apt/trusted.gpg.d/server-6.0.asc
2Create a list file for MongoDB.
Create the list file
/etc/apt/sources.list.d/mongodb-org-6.0.listfor 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 22.04 (Jammy).以下说明适用于Ubuntu 22.04(Jammy)。For other Ubuntu releases, click the appropriate tab.对于其他Ubuntu版本,请单击相应的选项卡。Create the
/etc/apt/sources.list.d/mongodb-org-6.0.listfile for Ubuntu 22.04 (Jammy):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
34Install the安装mongoshpackage.mongosh包装。mongoshsupports OpenSSL. You can also configuremongoshto use your system's OpenSSL installation.To install the latest stable version of
mongoshwith the included OpenSSL libraries:sudo apt-get install -y mongodb-mongosh
To install
mongoshwith your OpenSSL 1.1 libraries:sudo apt-get install -y mongodb-mongosh-shared-openssl11
To install
mongoshwith your OpenSSL 3.0 libraries:sudo apt-get install -y mongodb-mongosh-shared-openssl3
Next Steps接下来的步骤
Once you successfully install 成功安装mongosh, learn how to connect to your MongoDB deployment.mongosh后,学习如何连接到MongoDB部署。