繁体   English   中英

在PowerShell中安装Chocolatey的错误消息

[英]Error message installing Chocolatey in PowerShell

我正在尝试安装Chocolatey以与PowerShell一起使用。

建议的安装方法是复制并粘贴以下行。

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('http://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin

但是我收到以下错误:

At line:1 char:13
+ @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object  ...
+             ~~~~~~~~~~
Unexpected token '-NoProfile' in expression or statement.
At line:1 char:24
+ @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object  ...
+                        ~~~~~~~~~~~~~~~~
Unexpected token '-ExecutionPolicy' in expression or statement.
At line:1 char:150
+ ... nstall.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin
+                    ~~
The token '&&' is not a valid statement separator in this version.
At line:1 char:1
+ @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object  ...
+ ~~~~~~~~~~~
The splatting operator '@' cannot be used to reference variables in an expression. '@powershell' can be used only as
an argument to a command. To reference variables in an expression use '$powershell'.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

ExecutionPolicy设置为RemoteSigned,我正在运行Powershell v3

我尝试了一些应用安装代码而不是整行,但基本上,在@Powershell之后的任何东西都是意外的令牌。

您必须从cmd.exe(“标准”命令提示符)开始该行,而不是从PowerShell开始。

在PowerShell v3 +中最简单的方法是:

  1. 打开PowerShell窗口(以管理员身份运行)

  2. 检查PowerShell的版本是否大于3:

      $PSVersionTable.PSVersion 
  3. 是否允许执行PowerShell脚本?

     set-executionpolicy remotesigned 
  4. 在PowerShell中

     iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex 

我无法在Windows 10 64位操作系统安装上安装Chocolatey。 我被powershell not recognized as internal or external command 最后我找到了解决方案,所以对于那些遇到与我完全相同问题的人来说,这里有适合您的解决方案。

您收到此类错误的原因是因为未设置WindowsPowerShell路径。 所以请将Path设置为

%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\

转到Environment变量(见下文)。 您会看到Path变量,单击Edit,您会看到另一个弹出窗口,其中显示了一些路径。 现在单击New并复制粘贴上面的路径。 关闭CommandPrompt(admin)并再次打开它。 运行Chocolatey给出的命令,现在开始下载。

这是一个循序渐进的指南:

转到控制面板系统高级系统设置环境变量用户的用户变量 →选择路径变量 →单击编辑 →单击新建 →粘贴此%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\ →单击确定 →你'重做。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM