npm install angular: What It Really Installs and the Right Way to Install Angular

By · Published · Updated · 4 min read

Key takeaways

  • On npm, the package named "angular" is AngularJS (version 1.x), not modern Angular.
  • Install modern Angular with the Angular CLI: npm install -g @angular/cli, then ng new my-app.
  • AngularJS reached the end of its official support on 31 December 2021, so use Angular for new projects.
  • Inside an existing Angular project, run plain npm install. Do not run npm install angular.

If you typed npm install angular and then followed a tutorial that looked old, you are not alone. That command does not install the Angular framework that most courses teach today. It installs a different, older project called AngularJS. This guide explains the difference, the right commands, and how to fix a wrong install.

The short answer

Use the Angular CLI. Install Node.js, then run npm install -g @angular/cli, then create a project with ng new. You do not run npm install angular.

npm install -g @angular/cli
ng new my-app
cd my-app
ng serve

The last command, ng serve, starts a local development server. Open the address it prints in your browser. It is usually http://localhost:4200.

What npm install angular actually installs

On npm, the package named angular is AngularJS, the first version of the framework (version 1.x). Modern Angular is split into packages whose names start with @angular/, such as @angular/core and @angular/common. You do not install those one by one. The Angular CLI creates a project that already lists them.

AngularJS and Angular share a name, but they are different frameworks. Angular was rewritten from scratch and began with version 2. AngularJS reached the end of its official support on 31 December 2021, so it is not a good choice for a new project.

How to install Angular the right way

  1. Install Node.js from its official website. Choose a version that your Angular version supports. The Angular documentation lists the supported versions.
  2. Open a terminal and check that Node.js and npm work with node --version and npm --version.
  3. Install the Angular CLI for your whole computer with npm install -g @angular/cli.
  4. Check it with ng version. You should see the CLI version and your Node.js version.
  5. Create a project with ng new my-app. The CLI asks a few questions about styles and other options. The defaults are fine for learning.
  6. Go into the folder with cd my-app and start it with ng serve.

If you would rather not install the CLI globally, you can run npx @angular/cli new my-app. That downloads the CLI just for that one command.

Inside a project that already exists, you also do not run npm install angular. Run plain npm install. It reads the package.json file and installs everything that project needs.

How to tell AngularJS from Angular in a tutorial

  • AngularJS code puts attributes such as ng-app, ng-controller and ng-repeat in the HTML, and uses $scope in JavaScript.
  • AngularJS examples often load a script file from a CDN or import the package named angular.
  • Modern Angular code is written in TypeScript, in files that end in .ts, with classes that use @Component.
  • Modern Angular projects are created and run with the ng command.
  • Modern templates use @if and @for in recent versions, or *ngIf and *ngFor in older ones.
  • Check the date of the tutorial and the version it names. An old date is a warning sign.

If you are learning for a job today, learn Angular. AngularJS knowledge is mainly useful if you have to maintain an old application.

If you already ran npm install angular

It is easy to undo. In the folder where you ran it, remove the package:

npm uninstall angular

Then create a proper project with the Angular CLI, as shown above. If you only ran the command in an empty folder, you can also delete that folder and start again.

Common install problems

  • "ng" is not recognized, or "ng: command not found". The CLI is not installed, or your terminal cannot find the folder where npm puts global tools. Close and reopen the terminal, run npm install -g @angular/cli again and read the output for errors.
  • Permission errors (EACCES) on Linux or macOS. Avoid using sudo for global installs. Use a Node.js version manager, or point npm at a global folder that you own. The npm documentation explains how.
  • A message that your Node.js version is not supported. Update Node.js to a version that the Angular documentation lists for your Angular version.
  • Slow or failed downloads. Check your internet connection and try again. If you are behind a company proxy, ask your IT team for the npm proxy settings.

Where to go next

Our free Angular tutorial starts with installing Node.js and the Angular CLI and then explains what each file in a new project does. If you are preparing for interviews, the Angular interview questions are free to read.

Frequently asked questions

Does npm install angular install Angular?

No. The package named angular on npm is the old AngularJS (version 1.x). Modern Angular is created with the Angular CLI: npm install -g @angular/cli and then ng new my-app.

What is the difference between AngularJS and Angular?

AngularJS is the first version (1.x), built with JavaScript, controllers and $scope. Angular (version 2 and later) is a separate framework that was rewritten from scratch and uses TypeScript and components. AngularJS support ended on 31 December 2021.

Do I need Node.js to use Angular?

Yes. The Angular CLI and its build tools run on Node.js and are installed with npm, which comes with Node.js. Check the Angular documentation for the Node.js versions your Angular version supports.

How do I check which Angular version I have?

Run ng version in a terminal. Inside a project you can also look at the @angular/core line in package.json.

Can I install Angular without the CLI?

It is possible, but not recommended. The Angular CLI sets up TypeScript, the build and the project files for you, and almost every tutorial and course assumes you use it.

Sources