Angular CLI (Command Line Interface) is a powerful tool that helps developers quickly scaffold, develop, and maintain Angular applications. It provides commands for project creation, building, testing, and deploying applications efficiently.

Prerequisites

Before installing Angular CLI, ensure that you have the following requirements:

  • Node.js (LTS version recommended)
  • npm (comes bundled with Node.js)

You can check if Node.js and npm are installed by running:

node -v
npm -v

If not installed, download and install Node.js from Node.js official website.

Installing Angular CLI

Once Node.js is installed, install Angular CLI globally using npm:

npm install -g @angular/cli

To verify the installation, check the version:

ng version

This should display the Angular CLI version along with Angular dependencies.

Creating a New Angular Project

Use the following command to create a new Angular project:

ng new my-angular-app

You will be prompted to choose configurations such as routing and styling (CSS, SCSS, etc.). Once selected, the CLI will set up the project.

Navigate to the project directory:

cd my-angular-app

Running the Angular Application

To serve the application locally, use:

ng serve

The application will be available at http://localhost:4200/ on your Virtual Machine.

Understanding Angular CLI Commands

Here are some essential Angular CLI commands:

  • ng serve – Runs the application locally.
  • ng generate component component-name – Creates a new component.
  • ng build – Builds the application for production.
  • ng test – Runs unit tests.
  • ng e2e – Executes end-to-end tests.
  • ng add package-name – Installs an Angular package.
  • ng update – Updates Angular and dependencies.

Configuring Angular CLI

The angular.json file contains project configuration settings such as build, serve, and test options. You can customize build paths, output directories, and assets.

Conclusion

By following these steps, you have successfully installed and set up Angular CLI. This tool streamlines the development workflow, making it easier to manage Angular applications. Start exploring Angular CLI commands to enhance your development experience!