Installing Angular CLI Locally & Globally
Tags: angular, typescript, webdev, javascript
Published: 2022-09-15 21:12:28



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.

```js
npm install -g @angular/cli

```
_(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_

```js
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
```

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:

```js
ng new appName
```
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.

```js
npm install @angular/cli@V13.3.3
```
Notice the omitted -g and the version indication? here we are installing an angular CLI-specific version.

4. In that same folder create your starter app.

 ```js
ng new appName
```
**
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?