[求助] powershell安装Chocolatey 报错

环境:win10
使用 powershell 输入命令:
@“%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe” -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command “iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1’))” && SET “PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin”
报错了 报错信息:
所在位置 行:1 字符: 3

  • @“%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe” -NoPro …
  • ~
    here-string 标题后面和行尾之前不允许包含任何字符。
    • CategoryInfo : ParserError: (:slight_smile: , ParentContainsErrorRecordException
    • FullyQualifiedErrorId : UnexpectedCharactersAfterHereStringHeader

详情如图:

是要用chocolatey做包管理么?

这个命令是cmd下的不是power shell的 需要管理员方式启动cmd运行
是刚刚学到这里的同学吗?windows环境下涉及命令行的操作建议都使用虚拟机安装Linux或者使用windows10的WSL。也就是尽量在Linux环境下进行。

用cmd管理员方式执行的话 ,也是报错的:
使用“1”个参数调用“DownloadString”时发生异常:“请求被中止: 未能创建 SSL/TLS 安全通道。”
所在位置 行:1 字符: 1

  • iex ((New-Object System.Net.WebClient).DownloadString('https://chocol
  •   + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : WebException

powershell下用下面命令试试吧

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

也试过了 也是报错的

需要管理员模式运行powershell

可以了,多谢哈 :blush: :handshake:

不客气

win7安装的总结记录: 如果是win7 系统,在powershell 、 cmd 管理员运行方式执行对应的命令安装 报异常;
解决方式:1)先检测 powershell版本(输入命令:get-host)查看是2.0 还是2.0+;
如果是2.0 ,那么需要升级
2)升级powershell版本 ,下载地址:https://www.microsoft.com/en-us/download/details.aspx?id=54616
3)安装PowerShell5.1,至少需要.NET Framework 4.5.2,如果系统当前.NET Framework版本低于这个版本,需要先升级.NET Framework ,下载地址:https://www.microsoft.com/en-us/download/details.aspx?id=42642
4)下载Net Framework后 先进行安装
5) 安装PowerShell5.1升级包:
修改PowerShell执行脚本权限,输入命令:Set-ExecutionPolicy RemoteSigned -Force
没有报错信息的话,再输入:
Get-ExecutionPolicy 这个是验证权限策略是否修改正确,如果回车后看到输出RemoteSigned 则表示修改OK;
6) 执行脚本安装:
将下载的Win7AndW2K8R2-KB3191566-x86.zip压缩包解压到一个新的文件夹内,例如解压后的完整路径是“D:\Shell”。
7)在powershell里切换到解压好的路径 cd D:\Shell
8)执行里面的Install-WMF5.1.ps1脚本,输入命令:Install-WMF5.1.ps1;
如果有报错 ,则根据提示输入 ./Install-WMF5.1.ps1 进行安装
9)安装后重启电脑,再次输入get-host ,这时候powershell的版本应该是5.1的
10)再次以管理员身份输入安装chocolate的命令:Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1’))
这个时候就能安装成功了 ,测试一下安装结果输入:choco -v

1 个赞

我使用了上述介绍的方法,只是我俩需求的下载地址不一样罢了,其余都没改变,环境win10,powershell版本为5.1,但是会有以下报错New-Object : 使用“3”个参数调用“.ctor”时发生异常:“找不到中央目录结尾记录。” 所在位置 C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.p sm1:934 字符: 23 + … ipArchive = New-Object -TypeName System.IO.Compression.ZipArchive -Ar … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:slight_smile: [New-Object],MethodInvocationException + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand