Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error message installing Chocolatey in PowerShell

I'm trying to install Chocolatey to use with PowerShell.

The recommended way to install it is copy and paste the following line.

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

But I get the following error:

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 is set as RemoteSigned and I'm running Powershell v3

I tried some apply some bits of the installation code rather than the whole line, but basically, anything after @Powershell is an unexpected token.

like image 722
RafaelGP Avatar asked Feb 08 '13 11:02

RafaelGP


People also ask

How do I manually install Chocolatey?

Install via Command LinePress the Windows key and type "cmd". Select the Run as administrator option. Wait for the installation process to finish to start using Chocolatey. Note: Make sure to close and reopen the shell before using Chocolatey to ensure all the environment variables are loaded correctly.

How do you check if Choco is installed?

To verify that Chocolatey is installed, we will use the choco command. C:\WINDOWS\system32>choco Chocolatey v0. 10.15 Please run 'choco -? ' or 'choco -?

What is Chocolatey PowerShell?

Chocolatey is a package installer that's designed especially for working with Windows PowerShell. You can learn all about Chocolatey at the Chocolatey Gallery site. Chocolatey is also an open-source project. You can view and contribute to the Chocolatey source at Chocolatey GitHub.


2 Answers

In PowerShell v3+ the easiest way is:

  1. Open a PowerShell window (run as administrator)

  2. Check the version of PowerShell is greater than 3:

     $PSVersionTable.PSVersion
    
  3. Enable execution of PowerShell scripts?

    set-executionpolicy remotesigned
    
  4. In PowerShell

    iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
    
like image 196
Domenico Zinzi Avatar answered Sep 19 '22 14:09

Domenico Zinzi


You must start that line from cmd.exe (a "standard" command prompt), not from PowerShell.

like image 29
David Brabant Avatar answered Sep 16 '22 14:09

David Brabant