How to Install Angular: Step-by-Step Guide
To install
Angular, first install Node.js and npm. Then run npm install -g @angular/cli to install the Angular CLI globally, which helps create and manage Angular projects easily.Syntax
Use the following command to install the Angular CLI globally on your system:
npm install -g @angular/cli: Installs Angular CLI globally so you can usengcommands anywhere.
After installation, use ng new project-name to create a new Angular project.
bash
npm install -g @angular/cli
Example
This example shows how to install Angular CLI, create a new project, and start the development server.
bash
npm install -g @angular/cli
ng new my-angular-app
cd my-angular-app
ng serveOutput
ā Angular CLI installed globally
ā New Angular project 'my-angular-app' created
ā Development server running at http://localhost:4200/
Common Pitfalls
Common mistakes include:
- Not installing
Node.jsbefore Angular CLI, which causes errors. - Running
npm install @angular/cliwithout-g, which installs CLI only locally. - Not using a terminal with administrator rights on some systems, causing permission errors.
Always check your node and npm versions with node -v and npm -v before installing Angular CLI.
bash
Wrong: npm install @angular/cli Right: npm install -g @angular/cli
Quick Reference
Summary tips for installing Angular:
- Install
Node.js(version 16 or higher recommended). - Use
npm install -g @angular/clito install Angular CLI globally. - Create projects with
ng new project-name. - Run
ng serveto start the app locally.
Key Takeaways
Install Node.js and npm before installing Angular CLI.
Use 'npm install -g @angular/cli' to install Angular CLI globally.
Create new Angular projects with 'ng new project-name'.
Run 'ng serve' to start the development server and view your app.
Check Node.js and npm versions to avoid compatibility issues.