簡體   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