Installed angular-cli globally using (npm install -g angular-cli
) but when I\'m trying to create project using ng new my-project
it is throwing err
Make sure angular-cli is installed before trying to create a project. Windows users can install angular-cli without giving permission to command but MAC users have to use sudo before executing the command as follow:
sudo npm install -g angular-cli
Type a password when asked and press enter to proceed.
Adding %AppData%\npm
to the Win path have worked for me.
Source : https://github.com/angular/angular-cli/issues/1183 , the first comment.
For Mac users:
1) Install @angular/cli globally
$ sudo npm install -g @angular/cli
/usr/local/Cellar/node/10.0.0/bin/ng -> /usr/local/Cellar/node/10.0.0/lib/node_modules/@angular/cli/bin/ng
2) Create alias for ng
alias ng="/usr/local/Cellar/node/10.0.0/lib/node_modules/@angular/cli/bin/ng"
Done
If you have installed angular cli globally but ng isn't working, just do this:
echo -e "export PATH=$(npm prefix -g)/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
ng --version
First of all, check if your npm and node installed properly
with commands npm version
and node -v
.
If they are proper:
Find the root global Directory of NPM npm root -g
(it will
give you root of your global npm store)
Uninstall old angular cli with npm uninstall -g angular-cli
and npm cache clean
Reinstall new Version of angular npm install -g @angular/cli@latest
make an Alias of Name ng:
alias ng="C:/ProgramData/npm/node_modules/@angular/cli/bin/ng"
alias ng="<ath-to-your-global-node-modules>/<angular cli path till ng>"
(from answered Oct 20 '16 at 15:30 @m.zemlyanoi )
then to check you can type ng -v
First, angular-cli
is deprecated and has been replaced with @angular/cli
. So if you uninstall your existing angular-cli with npm uninstall angular-cli
, then reinstall the package with the new name @angular/cli you might get some conflicts. My story on Windows 7 is:
I had installed angular-cli and reinstalled using npm install -g @angular/cli
, but after doing some config changes to command-line tools, I started getting the ng command not found issue. I spent several hours trying to fix this but none of the above issues alone worked. I was able to fix it using these steps:
Install Rapid Environment Editor and remove any PATH entries for node, npm, angular-cli or @angular/cli. Node.js will be in your System path, npm and angular entries are in the User path.
Uninstall node.js and reinstall the current version (for me 6.11.1). Run Rapid Environment Editor again and make sure node.js and npm are in your System or User path. Uninstall any existing ng versions with:
npm uninstall -g angular-cli
npm uninstall -g @angular/cli
npm cache clean
Delete the C:\Users\%YOU%\AppData\Roaming\npm\node_modules\@angular folder.
Reboot, then, finally, run:
npm install -g @angular/cli
Then hold your breath and run:
ng -v
If you're lucky, you'll get some love. Hold your breath henceforward every time you run the ng command, because 'command not found' has magically reappeared for me several times after ng was running fine and I thought the problem was solved.