Facebooktwitterredditpinterestlinkedintumblr

If you are receiving the error message “-bash: ng: command not found” then it is likely that your package manager has failed to install one of the required packages. This can happen for a number of reasons, so let’s take a look at how to fix this problem.

What is Angular ng Command?

The Angular ng command is the Angular Command Line Interface (CLI) to use Angular. Creating a new Angular workspace with the ng command will give you an application skeleton. The initial app created by this process is at the top level of your folder.

Check if ng is Installed

The first thing you want to do is check if the ng command is installed on your computer. To do so, run this command:

$ ng version
-bash: ng: command not found

If you get the error message above, it means the ng command is unable to be located.

Run the ng Command Directly

If the path to the ng command is not set, you can still run ng by providing the full path to the program. Depending on the operating system you are running, type the following command:

On Debian Linux:

$ /usr/lib/node_modules/@angular/cli/bin/ng.js version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / ? \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 13.1.1
Node: 12.22.7
Package Manager: npm 6.14.15
OS: linux x64

Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1301.1 (cli-only)
@angular-devkit/core         13.1.1 (cli-only)
@angular-devkit/schematics   13.1.1 (cli-only)
@schematics/angular          13.1.1 (cli-only)

On macOS:

$ /usr/local/lib/node_modules/@angular/cli/bin/ng.js version
 
     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / ? \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 13.1.1
Node: 16.13.1
Package Manager: npm 8.1.2
OS: darwin x64

Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1301.1 (cli-only)
@angular-devkit/core         13.1.1 (cli-only)
@angular-devkit/schematics   13.1.1 (cli-only)
@schematics/angular          13.1.1 (cli-only)

If the command above succeeds, then the path to the ng command is missing. Follow the next section to fix your environment variable.

Update Your Environment Variables

The path to the ng command is missing from your environment variable. Depending on your operating system, follow the operations listed below.

On Windows:

  • Go to Control Panel and select System and Security option.
  • When a new dialog box opens, click on System.
  • Click on the Advanced system settings.
  • On the Advanced tab, click on Environment Variables.
  • Select PATH and click Edit.
  • Click New and add a new path for the ng program.
C:\Program Files\nodejs

On Debian Linux:

Add the path to the Linux environment variable:

export PATH="/usr/bin:$PATH"

On macOS:

Add the path to the macOS environment variable:

export PATH="/usr/local/bin:$PATH"

After adding the path, you should be able to run the ng command now.

Install the Angular CLI

You can install the Angular CLI using the npm command as shown below:

sudo npm install -g @angular/cli

Check the version of the ng command again by following the previous section. If successful, the ng version will be shown.

Re-install the Angular CLI

If the previous method doesn’t work, the installation may have gotten corrupted due to a bad cache. You can uninstall and re-install the Angular CLI again.

sudo npm uninstall -g @angular/cli
sudo npm cache clean
sudo npm install -g @angular/cli

After the re-installation, you should be able to run the ng command.

FAQ

Why is NG not Recognized?

When something goes wrong with your environment variables, this can cause an error in the operating system. You just need to follow a few important operations shown above and they should be able to solve them for you.

What is AngularJS?

Angular JS is a free and open-source framework used to build web applications. It’s developed by Google, but anyone can use it without restriction or fee.

What Does ng Stand for in Angular?

Ng stands for aNGular. All of the built-in directives that ship with it use this prefix. Similarly, you should avoid using ng on your own custom directive so as not to have any possible name collisions in future versions of Angular.

What is Node JS?

Node.js is a new way to build web servers that can be faster and more scalable than traditional ones, using event-driven programming instead of threads for logic distribution across multiple cores in the processor.

Leave a Comment