node.jsangularnpmcmdangular5

Why is it 'npm install -g @angular/cli'?


I know there are a lot of questions regarding this npm package installing, but I couldn't find the exact relevant answer.

I have already installed npm and also developed a few applications in my Visual Studio. Every time, before developing the new project of Angular, do we need to install npm again by typing "npm install -g @angular/cli" in cmd?


Solution

  • Once you have installed @angular/cli globally, in the next project you just need run ng new app-name. This command will create a folder named 'app-name' and then will install all dependencies locally, including @angular/cli.

    Installing @angular/cli globally allow you to use 'ng' command everywhere. It's required to install locally, because to your project, some specific @angular/cli version is required and newer versions maybe break.

    If your @angular/cli global is newer than the local project version, 'ng' will use the local @angular/cli instead, when you run 'ng serve', for example.

    Résumé: after installing using npm install -g @angular/cli, you will need just to run ng new app-name.