The angular CLI is available by default with major releases of the angular package. Therefore, once you install it, you can access it from the shell and manage your applications.
In this tutorial, we will discuss the “ng command not found” error, why it occurs, and how you can resolve it.”
Let’s get started.
What is the ng Command Not Found?
The error “ng command not found” occurs when your system’s shell cannot find the path to the ng cli binary.
There are three major causes of this error:
- The ng CLI is not installed.
- The ng CLI is located in a different directory.
- The ng CLI is not installed on a global level.
Let us see how we can resolve each of the above cases.
The ng CLI Not Installed
One of the major causes of the “ng command not found” error is the missing CLI utility. Before you can use the ng command, you will need to install it by running the command:
Once installed, you can check the angular cli version with the command:
The command should return detailed information about the installed angular cli.
An example output is shown below:
Node: 16.14.0
Package Manager: npm 8.5.1
OS: darwin arm64
Angular:
...
Package Version
------------------------------------------------------
@angular-devkit/architect 0.1400.0 (cli-only)
@angular-devkit/core 14.0.0 (cli-only)
@angular-devkit/schematics 14.0.0 (cli-only)
@schematics/angular 14.0.0 (cli-only)
The ng CLI is Installed in a Different Directory
If you have installed the angular cli in a different directory that is not part of the environment’s path, the system will be unable to locate and execute it.
You can resolve this by adding the directory where the ng command is installed to your path.
On Linux and macOS, edit your .bashrc file and add the line:
You can also add the line above for .zshrc file.
Save and close the file. To apply the changes, run the command:
$ source ~/.zshrc
The ng CLI Not Installed on a Global Level
Another common cause of the “ng command not found” error is the method of installing the angular cli.
To ensure that you can access the CLI outside of your current working environment, you need to install it with the -g flag.
The following commands allow you to uninstall and re-install the angular CLI on a global level.
$ sudo npm install -g @angular/cli
Once completed, you can test the installation by running the ng version command.
Closing
In this article, you learned the major causes of the “ng command not found” and three main methods of resolving it.
Thanks for reading!!