安装Chocolatey一文通
以管理员身份运行powershell
运行以下命令查看状态:
Get-ExecutionPolicy -List
会得到该效果(示例,不一样也罢):
在命令行中分别使用如下命令:
Set-ExecutionPolicy Bypass-Scope LocalMachine -Force
Set-ExecutionPolicy Bypass-Scope CurrentUser -Force
Set-ExecutionPolicy Bypass-Scope Process -Force
将Process , LocalMachine,CurrentUser的右侧状态改成Bypass。
运行结果情况:
- 有的会报出红色,但是如果出现 “已成功更新你的执行策略,但在更具体的作业域中定义的策略覆盖了该设置。” 这句话,则配置成功,这不是报错哦
- 有的会给出Y A N L 等选项让你选,打出 A 回车即可
进入Chocolatey官网
点击这里https://chocolatey.org/install进入官网
下滑页面,找到下图:
图片的**中下部分。**找到“现在运行以下指令 :”
下面的黑色选框里面是安装指令,在右侧按下那个按钮,复制,并在powerShell命令行中输入,回车
异常情况:
如果出现
警告: An existing Chocolatey installation was detected. Installation will
not continue. This script will not overwrite existing installations.
If there is no Chocolatey installation at 'C:\ProgramData\chocolatey',
delete the folder and attempt the installation again.Please use choco upgrade chocolatey to handle upgrades of Chocolatey
itself.
If the existing installation is not functional or a prior installation did
not complete, follow these steps:- Backup the files at the path listed above so you can restore your
previous installation if needed.- Remove the existing installation manually.- Rerun this installation script.- Reinstall any packages previously installed, if needed (refer to the libfolder in the backup).Once installation is completed, the backup folder is no longer needed and
can be deleted.
的黄色异常,那就是你已经下载过一个这个文件了,需要手动把这个文件夹删掉。在异常里面的路径就是你的文件的路径(以我为例)。寻找该文件的指令如下:
Test-Path "C:\ProgramData\chocolatey"
ProgramData有的时候如果找不见就是被隐藏了,把他显示就ok,进入,点击进入Chocolatey文件夹发现啥也没有,就把他删了,然后再次运行安装指令
至此,成功安装Chocolatey
恢复默认状态(可选)
在命令行中再次输入
Set-ExecutionPolicy Undifined-Scope LocalMachine -Force
Set-ExecutionPolicy AllDesigned-Scope CurrentUser -Force
Set-ExecutionPolicy Undifined-Scope Process -Force
将状态重置。也可根据自己的需求选择要不要恢复默认状态,主要是为了避免出现一些意想不到的问题
友情提示:
如果是在deepseek里面得到建议,需要使用Chocolatey安装某个东西,进而来学习安装Chocolatey的同志们,一定要先问清楚:那个东西到底能不能在Chocolatey的官方仓库中。否则可能会发现那个玩意不在Chocolatey安装库里面,导致你白下了