在 Windows 上以管理员身份运行时无法识别“choco”命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47861537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'choco' command not recognized when run as administrator on Windows
提问by Nicholas Kajoh
I installed Chocolatey as per the instructions on the website (https://chocolatey.org/install).
我按照网站 ( https://chocolatey.org/install)上的说明安装了 Chocolatey 。
The 'choco' command works fine when I run it normally on cmd but returns the following error when run as administrator:
当我在 cmd 上正常运行时,'choco' 命令工作正常,但以管理员身份运行时返回以下错误:
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.
choco install -y wget 7zip.commandline
如果不是以管理员身份运行,安装将失败。
How do I fix 'not recognized' error in admin cmd?
如何修复 admin cmd 中的“无法识别”错误?
回答by Krishnarjun Banoth
- 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/).
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"
Then press enter key from the keyboard. After few seconds you get complete info about current installation.
If you don't see any errors. Type
choco
orchoco -?
now.
- 首先,确保您使用的是命令提示符的管理 shell(https://www.howtogeek.com/194041/how-to-open-the-command-prompt-as-administrator-in-windows-8.1/)。
将以下文本复制到命令提示符中。
@"%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"
然后按键盘上的回车键。几秒钟后,您将获得有关当前安装的完整信息。
如果您没有看到任何错误。输入
choco
或choco -?
现在。
回答by Gursheesh Singh
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
然后重启命令提示符,现在choco安装成功
回答by akolliy
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 documentationwhich completely overwrites my env Path variable
.
在choco
environment variable
已经改变。我遇到了类似的问题,当我试着设置env variable
了Java SDK
,但我很快就意识到,当我跑commands
的呈现给我的文件,其完全覆盖我的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.
如果你确定你已经安装了 choco。检查您的System variables
并查找Path variable
它是否具有某些值,例如C:\ProgramData\chocolatey\choco.exe;C:\ProgramData\chocolatey\bin
如果没有add
。
And you can save you time by installing it. Installing via cmd line
您可以通过安装它来节省时间。通过 cmd 行安装
Powershell:
电源外壳:
Copy and Paste the code below to your PowerShell
将下面的代码复制并粘贴到您的 PowerShell 中
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
OR Window CMD.exe:
或窗口 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
安装后:运行choco
你会看到安装的chocolatey版本。矿
Chocolatey v0.10.14
Please run 'choco -?' or 'choco <command> -?' for help menu.
hopefully this help read more
希望这有助于阅读更多
回答by amit pandya
Hi for installing choco on your windows system, follow these steps:
嗨,在您的 Windows 系统上安装 choco,请按照下列步骤操作:
- First open cmd as admistrator.
- copy this command in the cmd (as administrator):
- 首先以管理员身份打开cmd。
- 在 cmd 中复制此命令(以管理员身份):
@"%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.
这将下载 choco 所需的依赖项并将其安装在您的 Windows 系统中。
For cross check run the choco command, for ex:
对于交叉检查运行 choco 命令,例如:
choco install -y nodejs.install python2 jdk8
回答by Nicholas Kajoh
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!
我能够使用C:\ProgramData\chocolatey\bin\choco.exe install -y wget 7zip.commandline
. 我仍然想知道为什么choco
当 cmd 以管理员身份运行时命令不起作用。我将不胜感激任何帮助。干杯!