PowerShell安装Chocolatey
文章目录
- 环境
- 背景
- 安装
- 参考
环境
- Windows 11 专业版
- PowerShell 7.5.1
- .NET Framework 4.0
- Chocolatey v2.4.3
背景
Chocolatey是Windows上的包管理工具,有点类似于Linux的 yum
和 apt
命令。比如,PowerShell里默认没有 grep
命令,则可以通过Chocolatey来安装 grep
:
choco install grep
安装
以管理员身份运行PowerShell。
运行 Get-ExecutionPolicy
,查看安全策略:
PS C:\Users\Administrator> Get-ExecutionPolicy
RemoteSigned
官方文档里说,如果返回值是 Restricted
,则需要运行 Set-ExecutionPolicy AllSigned
或者 Set-ExecutionPolicy Bypass -Scope Process
。
我这里貌似已经达到要求了,不需要改变。
安装Chocolatey:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
注:可能需要代理。
过一会儿,就安装好了。现在,就可以运行 choco
命令了:
PS C:\Users\Administrator> choco
Chocolatey v2.4.3
Please run 'choco -?' or 'choco <command> -?' for help menu.
接下来,就可以通过 choco install xxx
命令,来安装 grep
、 vim
、 which
等Linux常用命令和工具了。
参考
https://chocolatey.org/install