node: win11安装chocolatey时报错的解决

一,报错信息:

 powershell -c "irm https://community.chocolatey.org/install.ps1|iex"
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.7.3.
Downloading https://community.chocolatey.org/api/v2/package/chocolatey/2.7.3 to C:\Users\china\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip
Not using proxy.
Extracting C:\Users\china\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip to C:\Users\china\AppData\Local\Temp\chocolatey\chocoInstall
Installing Chocolatey on the local machine
& : 无法加载文件 C:\Users\china\AppData\Local\Temp\chocolatey\chocoInstall\tools\chocolateyInstall.ps1,因为在此系统上
禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:538 字符: 3
+ & $chocoInstallPS1
+   ~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [],PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
Ensuring Chocolatey commands are on the path
Ensuring chocolatey.nupkg is in the lib folder

问题原因:

没有权限运行脚本,打开终端时要用管理员方式,如图:

image

启动后放开执行脚本的权限,命令:

 Set-ExecutionPolicy Bypass -Scope Process -Force

如图:

image

二,报错信息

  powershell -c "irm https://community.chocolatey.org/install.ps1|iex"
警告: Files from a previous installation of Chocolatey were found at 'C:\ProgramData\chocolatey'.
警告: An existing Chocolatey installation was detected. Installation will not continue. This script will not overwrite
existing installations.
If there is no Chocolatey installation at '', 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 lib folder in the backup).

Once installation is completed, the backup folder is no longer needed and can be deleted.

问题原因:

发现chocolatey已安装了,目录在'C:\ProgramData\chocolatey'
原因是之前安装的部分的残留

解决:删除无用的安装目录:

 Remove-Item -Path "C:\ProgramData\chocolatey" -Recurse -Force

 

三,报错信息:

安装过程未报错,但安装完后choco命令执行报错:

 choco --version
choco : 无法将“choco”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正
确,然后再试一次。
所在位置 行:1 字符: 1
+ choco --version
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (choco:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

原因:安装完成后,当前窗口的环境变量未得到刷新
解决:关掉当前终端,重新打开一次即可

 

posted @ 2026-08-18 12:36  刘宏缔的架构森林  阅读(41)  评论(0)    收藏  举报