'ng' is not recognized as an internal or external command, operable program or batch file

前端 未结 19 1317
轻奢々
轻奢々 2021-01-31 01:31

I tried running npm install -g angular-cli

I also tried adding it to the Enviorment Variables under PATH: (C:\\Users\\Administrator\\AppData\\Roaming\\npm\\node

相关标签:
19条回答
  • 2021-01-31 02:15

    If angular cli is installed and ng command is not working then please see below suggestion, it may work

    In my case problem was with npm config file (.npmrc ) which is available at C:\Users{user}. That file does not contain line registry https://registry.npmjs.org/=true. When i have added that line command started working. Use below command to edit config file. Edit file and save. Try to run command again. It should work now.

    npm config edit
    
    0 讨论(0)
  • 2021-01-31 02:17

    This answer is based on the following answer by @YuSolution https://stackoverflow.com/a/44622211/4567504.

    In my case Installing MySQL changed my path variable and even after reinstalling @angular/cli globally many times I was not able to fix the issue.

    Solution:

    In command prompt, run the following command

    npm config get prefix
    

    A path will be returned like

    C:\Users{{Your_Username}}\AppData\Roaming\npm

    Copy this path and go to ControlPanel > System and Security > System, Click on Advanced System settings, go to advanced tab and select environment variable button like

    Now in User Variables box click on Path row and edit and in variable value box paste your copied path.

    Restart the command prompt and it will work

    0 讨论(0)
  • 2021-01-31 02:20

    note: you may lose values once system restarts.

    You can also add system environment variables without Admin rights in Windows 10.

    now don't restart, close any opened cmd or powershell, reopen cmd and test by ng version command if you see this it is confirmed working fine.

    hope this helps

    0 讨论(0)
  • 2021-01-31 02:21

    Short answer:

    Just install the latest version of nodejs and then restart your system.

    more description:

    It's related to Environment variables in your system at least as far as I know, you can make changes in path variable in your system as others talked about it in the current thread but the easiest way to solve this is installing nodejs!

    0 讨论(0)
  • 2021-01-31 02:23

    You don't need to set any path. Follow the below step to resolve the problem-

    Step 1- go to

    C:\Users\user\AppData\Roaming and delete npm, npm-update and npm-cache folder
    

    Step 2- run

    npm install -g @angular/cli@yourangularversion again.
    
    0 讨论(0)
  • 2021-01-31 02:24

    I was with the same problem and now discovered a working solution. After successful installation of node and angular CLI do the following steps.

    Open C:\usr\local and copy the path or the path where angular CLI located on your machine.

    Now open environment variable in your Windows, and add copied path in the following location:

    Advanced > Environment Variable > User Variables and System Variables as below image:

    That's all, now open cmd and try with any 'ng' command:

    0 讨论(0)
提交回复
热议问题