If you have landed on this page, it means you are using angular CLI and getting an ng command not found error. In this article, I will explain what are the causes and possible solutions for this error. Once you will follow this article step by step, you will be able to create new projects, develop and maintain your angular applications without further failures.
*** The ng stands and sounds like Angular that's why built-in directives that ships with Angular have this "ng" as the prefix.
If you are getting any of the following errors, follow this post to get it fixed.
- ng command not found mac
- ng command not found windows 10
- bash ng command not found Linux
- ng is not recognized as an internal or external command
- command ng not found ubuntu
- ng command not found in visual studio code
Table of Contents
- 1 Why is the ng command not found?
- 2 How to fix ng command not found error
- 3 Fix-1 Install Angular if not installed already in your system
- 4 Fix-2 Link NPM with angular/cli to fix ng command not found problem
- 5 Fix-3 Setup the variable correctly for your operating system
- 6 Fix-4 Check for admin or non-admin permission issues
- 7 Fix-5 Check ng command link especially in case of macOS
- 8 Fix-6 Setup alias for ng command
- 9 Fix-7 Update or reinstall Corrupt or old Angular/cli installation to resolve "ng command not found error"
- 10 Conclusion
Why is the ng command not found?
These are the possible reason for getting the ng command not found error -
- Angular is not installed on your machine
- NPM is not linked with Angular CLI
- Variable is not setup for correctly for Angular CLI, NPM and Nodejs
- Corrupt or obsolete Angular installation
- Missing alias to ng path
- Angular CLI link to /usr/loca/bin is missing case of macOS
How to fix ng command not found error
Below mentioned are the fixes that can be applied, based on your scenario and operating system.
Fix-1 Install Angular if not installed already in your system
The first step is to check whether you have @angular/cli is installed or not. Please make a note the older version "angular-CLI" has been depreciated. In case you have the old version, the suggestion is to install the latest angular version.
1.1 Check whether @angular/cli is installed
You must have npm and node.js installed correctly in your system as a pre-requisite before @angular/cli installation. The recommendation is to have the latest or compatible node.js and npm versions.
Run the following command to check @angular/cli package installation on your system
npm ls --global --depth 0
In this image, only nodemon is installed, @angular/cli module is not installed.
If the angular cli package is installed, then you can move to the next solution. Else run the following command to install angular cli on your system. Follow the "npm command not found" post, in case you have issues in npm.
How to install latest angular cli globally
- To install Angular cli on your system, follow these commands -
# npm install -g @angular/cli \\in case root user or $ sudo npm install -g @angular/cli
Side Note** - You will get warnings, in case angular cli or any existing module is not compatible with exiting node.js and npm and requires updates. The recommendation is to have the latest npm and node js installed.
For example, in this image, to install the latest @firstname.lastname@example.org, I would need minimum node version 12.2.0 and npm version 7.5.6. and my existing version is showing npm: 7.5.2 and am getting warnings of the unsupported engine.
So I must upgrade npm to the latest that's version 8.0.0 to avoid any future issues.
Close and reopen your terminal.
- Then Check
- Create a workspace and new project for your application
ng new my-app
If you are pretty new to Angular, then I will recommend reading these helpful Angular docs.
Fix-2 Link NPM with angular/cli to fix ng command not found problem
If you follow the correct approach during angular cli installation as shown in Fix-1, then you don't need to create any npm and angular links. But the fact is sometimes ng doesn't know about npm and you need to link it with angular/cli manually. So run the following command to link npm with angular/cli.
- Most of the ng command not found errors are fixed using the following npm link command
npm link @angular/cli or sudo npm link @angular/cli
Fix-3 Setup the variable correctly for your operating system
If you have followed all the required steps to install NPM, Nodejs and angular/cli correctly. You won't need to set up the path variable, it will automatically be setup during installation. But in case it doesn't then keep following further steps.
- To setup path variable in Unix, Linux or macOS -
to make it persistent, add the above command in the ~/.profile, ~/.bashrc or ~/.zshrc file based on the shell you are using.
In case of multiple projects and using different cli versions. The following command will help you to pick the local version (relative to the current directory), as long as you run the
ng command from within the root directory of your Angular (sub)project.
Then run the
source ~/.bashrc command to load the variable.
source ~/.bashrc or source ~/.zshrc
Follow these steps to set up a variable in Windows 10, if you are getting ng is not recognized as an internal or external command error.
- Search for environment variables in Windows 10 search box and select "edit enviornment variables"
- Click Open
- Select "Envrionment variables" tab
- Click on "PATH" in system variables and choose "Edit" button.
- Clilck New
- Add this path, replace "Your_Username" with your user and make sure you have node, npm and angular cli path setup correctly
In my case below mentioned are the paths, in the case of custom installation, these may differ in your case. Look for the right path and add it in the Environment variable of Windows 10.
- Reopen all command prompts or terminals and run
ng -vcommand to check verion.
Fix-4 Check for admin or non-admin permission issues
You may waste a lot of time, in case you don't understand the permissions role in the angular installation. If you are getting ng command not found error first time, while you were able to run it successfully before.
Then you need to ask yourself, have you installed the Angular before with running a terminal as administrator mode or vice versa. If you have installed angular/cli without admin mode, then run the angular command without admin mode command prompt only.
Similarly, if you have installed Angular/cli with administrator mode, then use admin mode only to run the ng command. Then you will not get any ng command errors.
*** And use command prompt (CMD) not Powershell to run
Many times it has been seen, the ng command doesn't establish the link with the /usr/local/bin directory. It happens with macOS users. So making a link manually helps to solve this ng command not found error for macOS.
Run this command to add the link manually using the ln command.
** You may need to replace the path "
usr/local/lib/node_modules/@angular/cli/bin/ng" with yours, in case any customize installations.
# ln -s usr/local/lib/node_modules/@angular/cli/bin/ng /usr/local/bin/ng ors $ sudo ln -s usr/local/lib/node_modules/@angular/cli/bin/ng /usr/local/bin/ng
Fix-6 Setup alias for ng command
Many times setting up an alias for ng command works and helps to fix ng command not found error.
- Remove existing or old alias of ng, in case any
- Add alias
ng -vcommand to check version.
Fix-7 Update or reinstall Corrupt or old Angular/cli installation to resolve "ng command not found error"
You may or may not know, that the angular-cli version has been depreciated now, my suggestion is to update it with the latest version @angular/cli.
To uninstall the old angular-cli version and install the latest one, follow these steps -
- Uninstall old version of angular-cli or @angular/cli and clean cache.
npm uninstall -g angular-cli npm uninstall -g @angular/cli npm cache clean
- Then you need to delete
C:\Users\%YOU%\AppData\Roaming\npm\node_modules\@angularfolder in case of Windows 10.
- For Linux or macOS users look for
node_modules/@angular/cli/bin/ngfolder and delete it.
- Reboot your system once is recommended. then run following command to install angular/cli.
npm install -g @angular/cli@latest
- Check ng version
The error "ng command not found" is a ghost and can appear any time, even if you are done everything right in the first place during installation. So equip yourself with the above troubleshooting steps and fight with this ghost.
I hope one or another solution will definitely work for you. Please let me know, which solution fixed your issue via your comments.