18

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?

5
  • 3
    The -g flag means it's installed globally on your machine, so no you don't need to reinstall every time. Commented Feb 16, 2018 at 14:28
  • If I dont do it this I got this error Cannot find module '@angular-devkit/core'
    – Juke
    Commented Feb 16, 2018 at 14:32
  • That's probably because you didn't run npm install for your project to install all the packages in packages.json
    – penleychan
    Commented Feb 16, 2018 at 14:35
  • this should be done before I do ng new myapp or after
    – Juke
    Commented Feb 16, 2018 at 15:07
  • Re "Visual Studio": Do you mean "Visual Studio Code"? Commented Nov 1, 2023 at 3:19

2 Answers 2

23

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.

10

No. You only need to run

npm i -g @angular/cli

Once ever (or when you update in the future).

And that's used to generate Angular apps and different Angular CLI-related terminal commands. You don't need to run it ever again after that. But you will need to install it locally in your project, so that certain things will work properly.

4
  • npm i -g @angular/cli , what i stands for ?
    – Juke
    Commented Feb 16, 2018 at 14:37
  • install. You can type i or install Commented Feb 16, 2018 at 14:37
  • you said No and you say to run again with the same command I am little confused
    – Juke
    Commented Feb 16, 2018 at 15:06
  • What I meant was this: npm install -g @angular/cli (to install Angular on your computer). Then, when you create a project via ng new projectName, then it automatically will run npm install @angular/cli --save-dev. Commented Feb 16, 2018 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.