DEV Community

Cover image for Installing Angular CLI Locally & Globally
Wisdom John ikoi
Wisdom John ikoi

Posted on

Installing Angular CLI Locally & Globally

Angular is a JavaScript Framework and it is one of the world most powerful web development platform.

Starting an angular project will require an IDE and a development environment. Setting up a project can be done in two ways either by setting up on the cloud or by setting up a local environment and workspace.

While working directly in a cloud-based environment is an awesome experience, setting up your coding project in a local environment is mostly preferred especially on a large project and code base.

This article explains how to set up your Angular development environment locally or globally using the Angular CLI tool.

Globally

To install angular CLI globally Run the following command on your VSCode Terminal or Command Prompt.

npm install -g @angular/cli

Enter fullscreen mode Exit fullscreen mode

(Optional)

_The following is angular's execution policy, see the official documentation:

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies_

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
Enter fullscreen mode Exit fullscreen mode

You have successfully installed the angular CLI globally with the latest version of angular.

You can now create an angular application in any directory it will listen for the global CLI.

To create a new workspace navigate to a specific folder in your terminal and run:

ng new appName
Enter fullscreen mode Exit fullscreen mode

A starter app is created, select which feature should be installed alongside your initial app and press enter.

now your app is created, and depends on the angular CLI version that was installed globally.

Locally

While creating subsequent angular applications (ng apps) you might want a lesser version and you may not want to re-install your global CLI because it will affect other apps that depend on it.

This is where local CLI installation comes in. The local CLI serves as a dependency to an ng-app or a set of ng-apps ignoring the Global CLI.

which means the Global CLI can be angular V14 and the local CLI supports angular V13 making all apps that depend on it respond to that angular version.

The local CLI serves as a guard and restricts apps from listening to the global CLI.

To set up an angular application locally do the following.

  1. Open a folder on your code editor. i.e VSCode, Atom, Brackets e.t.c.

  2. On the terminal navigate to the folder you want to install angular CLI on locally.

  3. Run the following command.

npm install @angular/cli@V13.3.3
Enter fullscreen mode Exit fullscreen mode

Notice the omitted -g and the version indication? here we are installing an angular CLI-specific version.

  1. In that same folder create your starter app.
ng new appName
Enter fullscreen mode Exit fullscreen mode

**
Conclusion**

Any Application you generate within that folder/directory is restricted to the Angular locally installed CLI version.

While the ones created outside the folder automatically listen for the global CLI and subscribe to it as its dependency.

Installing Angular CLI locally or globally has its own effect on the development process, you can choose to subscribe to the global CLI or create a local CLI for your individual angular application to depend on.

Extra

I prefer to localize my angular projects and give them standalone CLI as I see fit, what do you prefer?

Top comments (3)

Collapse
 
naucode profile image
Al - Naucode

That was a nice read! Liked, bookmarked and followed, keep the good work!

Collapse
 
xenxei46 profile image
Wisdom John ikoi

Thank you.

Collapse
 
manojmj profile image
Manojkumar

very informative content