How to Run Angular Commands (ng command) in Windows PowerShell

This article will show how you can run Angular commands (ng command) in Windows PowerShell.

After installing Angular CLI on Windows, you may encounter issues running ng commands in PowerShell due to script execution policies.

The issue

ng : File C:\Users\<username>\AppData\Roaming\npm\ng.ps1 cannot be loaded. The file
C:\Users\<username>\AppData\Roaming\npm\ng.ps1 is not digitally signed...

This tutorial provides two solutions to overcome this problem: by setting the PowerShell execution policy or by deleting the ng.ps1 file.

By Setting the PowerShell Execution Policy

In Windows, PowerShell script execution is disabled by default for security reasons. To run Angular CLI commands successfully, you can adjust the execution policy.

Follow the steps below:

Open PowerShell as Administrator

Right-click on the PowerShell icon and choose “Run as Administrator” to open an elevated PowerShell prompt.

Set the Execution Policy

Run the following command to set the execution policy for the current user:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

You will be prompted to confirm the change. Type Y for yes and press Enter.

Verify Angular Commands

After setting the execution policy, verify that Angular commands work by checking the Angular version:

ng version

If successful, you should see information about the installed Angular version.

By Deleting ng.ps1 File

Another approach to resolve the issue is by removing the ng.ps1 file. Follow the steps below:

Delete ng.ps1

Navigate to the following directory:

Remove-Item -Path $env:APPDATA\npm\ng.ps1

Clear npm Cache

Clear the npm cache by running the following command:

Remove-Item -Path $env:APPDATA\npm-cache\* -Recurse -Force

Run Angular Commands

Now you can run Angular commands in PowerShell without encountering script signing issues.


Note:

  • Keep in mind that changing the execution policy or deleting the ng.ps1 file may have security implications. Make sure you understand the risks involved and only execute scripts from trusted sources.

By following either of these methods, you should be able to run Angular CLI commands smoothly in Windows PowerShell.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top