Installing Angular CLI
Angular CLI is a command-line tool used to create, develop, test, build and manage Angular applications.
What is Angular CLI?
Angular CLI stands for Angular Command Line Interface. It provides a set of commands that help developers create and manage Angular applications from the terminal.
Instead of manually creating every Angular file and folder, Angular CLI can automatically generate the required project structure and development files.
In Simple Words
Angular CLI is a development tool that makes it easier to create, run, generate and build Angular applications.
Why Do We Need Angular CLI?
Create
Create new Angular applications quickly.
Generate
Generate components, services and other files.
Develop
Run Angular applications using the development server.
Build
Build Angular applications for deployment.
Prerequisite
Before installing Angular CLI, make sure that Node.js and npm are installed on your system.
Node.js
Required runtime environment.
npm
Required package manager.
Angular CLI
Angular development tool.
Step 1: Check Node.js
Open Command Prompt or Terminal and check whether Node.js is installed.
node --version
Expected Output
The terminal displays the installed Node.js version.
Step 2: Check npm
npm is normally installed together with Node.js. Verify the npm installation using the following command.
npm --version
Expected Output
The terminal displays the installed npm version.
Step 3: Install Angular CLI
Now install Angular CLI globally using npm. Open Command Prompt or Terminal and execute:
npm install -g @angular/cli
What does this command mean?
npm is the package manager, install installs a package, -g installs it globally, and @angular/cli is the Angular CLI package.
A global installation allows the Angular CLI command to be used from different project folders.
Angular CLI Installation Flow
Step 4: Verify Angular CLI Installation
After Angular CLI installation is completed, verify the installation using the following command:
ng version
Expected Output
Angular CLI displays information about the installed Angular CLI version, Node.js version and related packages.
Node: [version]
Package Manager: npm [version]
What is the ng Command?
After installing Angular CLI, the ng command becomes available in the terminal.
The ng command is used for different Angular development operations such as creating applications, generating components, running the development server and building applications.
ng
Expected Result
Angular CLI displays the available Angular commands and options.
Important Angular CLI Commands
| Command | Purpose |
|---|---|
ng version
|
Display Angular CLI version information |
ng new ProjectName
|
Create a new Angular application |
ng serve
|
Start the Angular development server |
ng generate component name
|
Generate a new Angular component |
ng generate service name
|
Generate an Angular service |
ng build
|
Build the Angular application |
Example: Generate a Student Component
Suppose we want to create a component for displaying student information.
ng generate component student
Angular CLI generates the required component files automatically.
Common Installation Issues
'ng' is not recognized
If the terminal does not recognize the ng command, close the terminal and open it again.
Installation Permission Issue
If npm shows a permission-related error, open the terminal with appropriate permissions and try the installation again.
Check Node.js and npm
Make sure Node.js and npm are installed correctly before installing Angular CLI.
Summary
Angular CLI is a command-line tool used to create, generate, develop and build Angular applications.
The Angular CLI can be installed globally using npm install -g @angular/cli.
After installation, use ng version to verify the Angular CLI installation.
In the next topic, we will learn how to Create an Angular Application.