ng: command not found while creating new project using angular-cli

后端 未结 30 2690
忘掉有多难
忘掉有多难 2020-11-28 23:42

Installed angular-cli globally using (npm install -g angular-cli) but when I\'m trying to create project using ng new my-project it is throwing err

相关标签:
30条回答
  • 2020-11-29 00:13

    For Mac run

    npm install -g @angular/cli@latest

    then run

    alias ng="/usr/local/lib/node_modules/node/lib/node_modules/@angular/cli/bin/ng"
    

    Check if working

    ng version
    
    0 讨论(0)
  • 2020-11-29 00:15

    The issue is simple, npm doesn't know about ng

    Just run npm link @angular/cli and it should work seamlessly.

    0 讨论(0)
  • 2020-11-29 00:15

    This is how I made it worked for me :).

    1 - npm link @angular/cli

    It will return you the path of cli, which will look like this

    /usr/local/Cellar/node/11.3.0_1/lib/node_modules/@angular/cli
    

    For this part, /11.3.0_1 please replace this with your respective node version that can be found by typing node --version

    2 - cd ~/

    3 - open .bash_profile

    In the bash profile create an alias for cli like this,

    alias ng="/usr/local/Cellar/node/11.3.0_1/lib/node_modules/@angular/cli/bin/ng"

    4 - source ~/.bash_profile

    This is how your .bash_profile will look like once you add alias to it.

    Now typing ng in the terminal will display output shown in attached snapshot.

    I hope this answer will be helpful.

    0 讨论(0)
  • 2020-11-29 00:15

    try this :

    alias ng="~/node_modules/@angular/cli/bin/ng"

    0 讨论(0)
  • 2020-11-29 00:15

    This works to update your angular/cli //*Global package (cmd as administrator)

    npm uninstall -g @angular/cli
    npm cache verify
    npm install -g @angular/cli@latest
    
    0 讨论(0)
  • 2020-11-29 00:15

    If you have a MacOS computer (mine is MOJAVE 10.14.2), just add these lines to the end of your ~/.bash_profile file:

    export ANGULAR=~/.nvm/versions/node/v10.8.0/bin/ng
    export PATH=$ANGULAR:$PATH
    

    Notice that v10.8.0 is the version of my installed Node.js. To get which version is yours, run this:

    node --version
    

    When done, reload it via your terminal/bash:

    cd ~
    source .bash_profile
    

    After doing these steps you should be able to run your ng binary file.

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