使用 Windows PowerShell (管理员) 安装 Chocolatey

安装 Chocolatey 是一个相对简单的过程。以下是详细的步骤:

步骤 1:打开 PowerShell 作为管理员

  1. Win + X,然后选择 Windows PowerShell (管理员)Windows Terminal (管理员)
  2. 如果出现用户账户控制对话框,点击 继续。

步骤 2:运行 Chocolatey 安装脚本

  1. 在 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:验证安装

  1. 等待安装脚本完成。安装过程可能需要几分钟时间。

  2. 关闭并重新打开 PowerShell,以确保新的环境变量生效。

  3. 运行以下命令来验证 Chocolatey 是否安装成功

    choco -v
    
    PS C:\WINDOWS\system32> choco -v
    2.4.0
    

    如果安装成功,你会看到 Chocolatey 的版本号。

示例步骤

以下是完整的示例步骤:

  1. 打开 PowerShell 作为管理员

    • Win + X 键。
    • 选择 Windows PowerShell (管理员)Windows Terminal (管理员)
  2. 运行安装脚本

    Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
    
  3. 等待安装完成

    • 安装过程可能需要几分钟时间,耐心等待。
  4. 验证安装

    • 关闭并重新打开 PowerShell。
    • 运行以下命令:
      choco -v
      
    • 如果安装成功,你会看到类似以下的输出:
      1.3.5
      

其他注意事项

  1. 防火墙和安全软件

    • 如果你在安装过程中遇到网络连接问题,可能是由于防火墙或安全软件阻止了下载。请确保这些软件允许访问 https://chocolatey.org
  2. 代理设置

    • 如果你在企业网络中使用代理服务器,可能需要配置代理设置。可以在安装脚本中添加代理参数,例如:
      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。

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值