25

I installed Chocolatey as per the instructions on the website (https://chocolatey.org/install).

The 'choco' command works fine when I run it normally on cmd but returns the following error when run as administrator:

C:\WINDOWS\system32>choco install -y wget 7zip.commandline
'choco' is not recognized as an internal or external command,
operable program or batch file.

The install choco install -y wget 7zip.commandline fails if not run as administrator.

How do I fix 'not recognized' error in admin cmd?

Nicholas Kajoh
  • 1,022
  • 2
  • 16
  • 27
  • Search this site for *not recognized as an internal or external command*, which will turn up literally thousands of existing posts regarding that same issue. In fact, you were shown many of them as potential duplicates when you posted; they're over there in the **Related** list --->>> Certainly at least one of them will tell you how to fix the problem. Doing at least a simple search here is part of making an effort to find a solution yourself before posting. – Ken White Dec 18 '17 at 02:54
  • I've been going through such posts for the past 30 minutes. The command doesn't still work when I run cmd as administrator. I've checked the PATH. It's properly set. Yet the command only works when I open cmd normally (not as admin). Please can you point me to any question that mentions running cmd as admin? – Nicholas Kajoh Dec 18 '17 at 03:10
  • In case you're using the newer Windows Terminal: you can't just open a new tab. You need to restart the entire Windows Terminal application to recognize env var updates. – JasonCoder Sep 17 '20 at 19:12

7 Answers7

34
  1. First, ensure that you are using an administrative shell of command prompt(https://www.howtogeek.com/194041/how-to-open-the-command-prompt-as-administrator-in-windows-8.1/).
  2. Copy the below text into the command prompt.

    @"%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"
    
  3. Then press enter key from the keyboard. After few seconds you get complete info about current installation.

  4. If you don't see any errors. Type choco or choco -? now.

Reference

Ojonugwa Jude Ochalifu
  • 23,935
  • 25
  • 104
  • 122
Krishnarjun Banoth
  • 1,047
  • 1
  • 11
  • 26
17

First Open the Command prompt as administrator and then run -

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

And then restart the Command prompt, now choco is successfully installed

12

The choco environment variable has been altered. I ran into a similar problem when I tried setting env variable for Java SDK, but I was quick to recognize it when I ran the commands presented to me in the documentation which completely overwrites my env Path variable.

If you are sure you've choco installed. Check your System variables and look for Path variable if it has some values like C:\ProgramData\chocolatey\choco.exe;C:\ProgramData\chocolatey\bin if not add it.

And you can save you time by installing it. Installing via cmd line

Powershell:

Copy and Paste the code below to your PowerShell

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

OR Window CMD.exe:

@"%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"

After installation: run choco you see the version of chocolatey installed. Mine

Chocolatey v0.10.14
Please run 'choco -?' or 'choco <command> -?' for help menu.

hopefully this help read more

akolliy
  • 832
  • 5
  • 13
1

Just correcting what @Krishnarjun Banoth has given in the answer:

powershell -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"

You don't have to add the PATH variable because choco will automatically add itself to PATH.

0

I was able to get the installation to work using C:\ProgramData\chocolatey\bin\choco.exe install -y wget 7zip.commandline. I'm still wondering why the choco command isn't working when cmd is run as administrator. I would appreciate any help. Cheers!

Nicholas Kajoh
  • 1,022
  • 2
  • 16
  • 27
0

Hi for installing choco on your windows system, follow these steps:

  • First open cmd as admistrator.
  • copy this command in the cmd (as administrator):
@"%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"

This will download the required dependency for choco and install it in your windows system.

For cross check run the choco command, for ex:

choco install -y nodejs.install python2 jdk8
DINA TAKLIT
  • 4,946
  • 7
  • 42
  • 50
amit pandya
  • 1,174
  • 11
  • 20
  • 1
    Not sure why this got downvoted, but I also found that you had to use cmd. Powershell didn't work for me, but running the same thing in cmd it worked immediately. – Grant Curell Aug 18 '20 at 14:43
0

Open command prompt in administrator mode and run this command:

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command " [System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
Adrian Mole
  • 30,672
  • 69
  • 32
  • 52