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
- Install Node.js from its official website. Choose a version that your Angular version supports. The Angular documentation lists the supported versions.
- Open a terminal and check that Node.js and npm work with node --version and npm --version.
- Install the Angular CLI for your whole computer with npm install -g @angular/cli.
- Check it with ng version. You should see the CLI version and your Node.js version.
- 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.
- 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.