安装 Chocolatey 是一个相对简单的过程。以下是详细的步骤:
步骤 1:打开 PowerShell 作为管理员
- 按
Win + X键,然后选择Windows PowerShell (管理员)或Windows Terminal (管理员)。 - 如果出现用户账户控制对话框,点击
是继续。
步骤 2:运行 Chocolatey 安装脚本
- 在 PowerShell 中运行以下命令:
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
S\system32> Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) Forcing web requests to allow TLS v1.2 (Required for requests to Chocolatey.org) Getting latest version of the Chocolatey package for download.
Not using proxy.
Getting Chocolatey from https://community.chocolatey.org/api/v2/package/chocolatey/2.4.0.
Downloading https://community.chocolatey.org/api/v2/package/chocolatey/2.4.0 to C:\Users\dgq\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip
Not using proxy.
Extracting C:\Users\dgq\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip to C:\Users\dgq\AppData\Local\Temp\chocolatey\chocoInstall
Installing Chocolatey on the local machine
Creating ChocolateyInstall as an environment variable (targeting 'Machine')
Setting ChocolateyInstall to 'C:\ProgramData\chocolatey'
WARNING: It's very likely you will need to close and reopen your shell
before you can use choco.
Restricting write permissions to Administrators
We are setting up the Chocolatey package repository.
The packages themselves go to 'C:\ProgramData\chocolatey\lib'
(i.e. C:\ProgramData\chocolatey\lib\yourPackageName).
A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin'
and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName'.
Creating Chocolatey CLI folders if they do not already exist.
chocolatey.nupkg file not installed in lib.
Attempting to locate it from bootstrapper.
PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Adding...
警告: Not setting tab completion: Profile file does not exist at 'E:\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'.
Chocolatey CLI (choco.exe) is now ready.
You can call choco from anywhere, command line or powershell by typing choco.
Run choco /? for a list of functions.
You may need to shut down and restart powershell and/or consoles
first prior to using choco.
Ensuring Chocolatey commands are on the path
Ensuring chocolatey.nupkg is in the lib folder
步骤 3:验证安装
-
等待安装脚本完成。安装过程可能需要几分钟时间。
-
关闭并重新打开 PowerShell,以确保新的环境变量生效。
-
运行以下命令来验证 Chocolatey 是否安装成功:
choco -vPS C:\WINDOWS\system32> choco -v 2.4.0如果安装成功,你会看到 Chocolatey 的版本号。
示例步骤
以下是完整的示例步骤:
-
打开 PowerShell 作为管理员:
- 按
Win + X键。 - 选择
Windows PowerShell (管理员)或Windows Terminal (管理员)。
- 按
-
运行安装脚本:
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) -
等待安装完成:
- 安装过程可能需要几分钟时间,耐心等待。
-
验证安装:
- 关闭并重新打开 PowerShell。
- 运行以下命令:
choco -v - 如果安装成功,你会看到类似以下的输出:
1.3.5
其他注意事项
-
防火墙和安全软件:
- 如果你在安装过程中遇到网络连接问题,可能是由于防火墙或安全软件阻止了下载。请确保这些软件允许访问
https://chocolatey.org。
- 如果你在安装过程中遇到网络连接问题,可能是由于防火墙或安全软件阻止了下载。请确保这些软件允许访问
-
代理设置:
- 如果你在企业网络中使用代理服务器,可能需要配置代理设置。可以在安装脚本中添加代理参数,例如:
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials; (New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
- 如果你在企业网络中使用代理服务器,可能需要配置代理设置。可以在安装脚本中添加代理参数,例如:
通过以上步骤,你应该能够成功安装 Chocolatey。

1494

被折叠的 条评论
为什么被折叠?



