How to uninstall/upgrade Angular CLI?

AngularAngular Cli

Angular Problem Overview


When I try to create a new project with Angular CLI, with:

ng n app

I get this error:

> fs.js:640 return binding.open(pathModule._makeLong(path), > stringToFlags(flags), mode); > ^ TypeError: path must be a string or Buffer > at TypeError (native)

How can I upgrade or uninstall Angular CLI?

Angular Solutions


Solution 1 - Angular

Using following commands to uninstall :

npm uninstall -g @angular/cli
npm cache clean --force

To verify: ng --version /* You will get the error message, then u have uninstalled */

Using following commands to re-install :

npm install -g @angular/cli

Notes :

  • Using --force for clean all the caches

  • On Windows run this using administrator

  • On Mac use sudo ($ sudo <command>)

  • If you are using npm>5 you may need to use cache verify instead. ($ npm cache verify)

Solution 2 - Angular

None of the above solutions alone worked for me. On Windows 7 this worked:

Install Rapid Environment Editor and remove any entries for node, npm, angular-cli or @angular/cli

Uninstall node.js and reinstall. 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.

Solution 3 - Angular

Run the following commands to get the very latest of angular

npm uninstall -g @angular/cli
npm cache verify
npm install -g @angular/cli@latest
ng version

Solution 4 - Angular

> Regular solution, that does not work always:

npm uninstall -g @angular/cli
npm cache verify
npm install -g @angular/cli

> Other more drastic solution:

  • Uninstall Angular CLI globally
npm uninstall -g @angular/cli
  • Uninstall Node.js & npm with uninstaller
  • Remove every environment variables related to Node.js & npm
  • Delete folders C:\Users\<user>\AppData\Roaming\npm and C:\Users\<user>\AppData\Roaming\npm-cache
  • Verify these commands are ko:
ng version
npm -v
node -v
npm install -g @angular/cli
  • Finally, check your global Angular CLI version:
ng version

Solution 5 - Angular

remove global reference

npm uninstall -g angular-cli
npm cache clean

Solution 6 - Angular

Ran into this recently myself on mac, had to remove the ng folder from /usr/local/bin. Was so long ago that I installed the Angular CLI, I'm not entirely sure how I installed it originally.

Solution 7 - Angular

Angular cli has moved to @angular/cli, so as from the github readme,

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

Solution 8 - Angular

I tried all the above things, and still ng as sticking around globally. So in powershell I ran Get-Command ng, and then it became clear what my problem was. I was using yarn heavily in the past, and all the old angular cli packages were also installed globally in the yarn cache location. I deleted my yarn cache for good measure, but probably could have just updated the global angular cli via yarn. In any case, I hope this helps remind some of you that if you use yarn, then global commands like ng can also live in another path than where npm puts them.

Solution 9 - Angular

Well inline with many answers above even I had the issue where I wasn't able to create a new-app with angular cli 9.1.0 on Mac OS 10.15.3 . My issue was resolved by uninstalling the angular cli, cleaning the cache and re-installing the angular cli.

npm uninstall -g @angular/cli

Verify installation status with ng --version

npm cache verify
npm install -g @angular/cli

Try creating new app with ng new my-app now to see if the above helps.

Solution 10 - Angular

To uninstall it globally just run below command:

npm uninstall -g @angular/cli

Once it is done, clear your cache by running below command:

npm cache clean

Now, to install the latset version of Angular, just run:

npm install -g @angular/cli@latest

For details about Angular CLI, take a look at Angular introduction and CLI guide

Solution 11 - Angular

Installed with yarn

If you added the angular cli with yarn, you can only remove (and therefor update) it the same way. See the short but great answer here: https://stackoverflow.com/a/56192531/13226740

This helped me a lot after one hour of desperate search, because I forgot, that I installed the CLI via yarn.

Solution 12 - Angular

I always use the following commands before upgrading to latest . If it is for Ubuntu prefix : 'sudo'

npm uninstall -g angular-cli
npm cache clean
npm install -g angular-cli@latest

Solution 13 - Angular

If nothing works for, you can also check your globally installed node modules like so:

cd /usr/local/lib/node_modules/npm/node_modules

Then remove the @angular folder:

rm -R @angular

And reinstall the angular-cli by running:

npm install -g @angular/cli

Solution 14 - Angular

use following command if you installed in globally,

 npm uninstall -g angular-cli

Solution 15 - Angular

Run this command

npm uninstall angular-cli

Solution 16 - Angular

Not the answer for your question, but the answer to the problem you mentioned:

It looks like you have wrong configuragion file for the angular-cli version you are using.

In angular-cli.json file, try to change the following:

from:

  "environmentSource": "environments/environment.ts",
  "environments": {
    "dev": "environments/environment.ts",
    "prod": "environments/environment.prod.ts"
  }

to:

  "environments": {
    "source": "environments/environment.ts",
    "dev": "environments/environment.ts",
    "prod": "environments/environment.prod.ts"
  }

Solution 17 - Angular

 $ npm uninstall -g angular-cli 
 $ npm cache clean 
 $ npm install -g angular-cli

Solution 18 - Angular

I got similar issue while I was creating a new angular app. The problem for me was due to npm 7 and I just downgraded npm.

npm install -g npm@6

If we need to uninstall or upgrade cli, we can use these commands

npm uninstall -g @angular/cli
npm cache clean --force

then reinstall using the command

npm install -g @angular/cli

Solution 19 - Angular

For the error I was facing:

> ERR! code ENOTEMPTY npm ERR! syscall rename npm ERR! path > /usr/local/lib/node_modules/@angular/cli npm ERR! dest > /usr/local/lib/node_modules/@angular/.cli-G39XYeT9 npm ERR! errno -66 > npm ERR! ENOTEMPTY: directory not empty, rename > '/usr/local/lib/node_modules/@angular/cli' -> > '/usr/local/lib/node_modules/@angular/.cli-G39XYeT9'

I used the following steps and it worked:

#### uninstalling globally installed libs
sudo npm uninstall -g @angular/cli
#### uninstall other libs
sudo npm uninstall -g

#### uninstalling node
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
rm -rf /Users/[homedir]/.npm

#### reinstall node
https://nodejs.org/en/download/

#### update npm to latest
sudo npm install -g npm

#### reinstall angular-cli
sudo npm install -g @angular/cli

Solution 20 - Angular

Simplest workaround to continue working in your project is comment line 25 of node_modules/angular-cli/bin/ng:

// Version.assertPostWebpackVersion();

Until it is fixed properly.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRohanArihantView Question on Stackoverflow
Solution 1 - AngularSantosh PillaiView Answer on Stackoverflow
Solution 2 - AngularVanAlbertView Answer on Stackoverflow
Solution 3 - AngularStanley MohlalaView Answer on Stackoverflow
Solution 4 - AngularvebenView Answer on Stackoverflow
Solution 5 - AngularA.T.View Answer on Stackoverflow
Solution 6 - AngularjassokView Answer on Stackoverflow
Solution 7 - AngularAll Іѕ VаиітyView Answer on Stackoverflow
Solution 8 - AngularRafeView Answer on Stackoverflow
Solution 9 - AngularGururaj BirajdarView Answer on Stackoverflow
Solution 10 - AngularUttam Kumar MishraView Answer on Stackoverflow
Solution 11 - AngularTinoView Answer on Stackoverflow
Solution 12 - AngularYashwanth Chowdary KataView Answer on Stackoverflow
Solution 13 - AngulartimoblumeView Answer on Stackoverflow
Solution 14 - AngularAjith K PView Answer on Stackoverflow
Solution 15 - AngularJulian BiciView Answer on Stackoverflow
Solution 16 - AngularGal TamirView Answer on Stackoverflow
Solution 17 - AngularLekensView Answer on Stackoverflow
Solution 18 - AngularRohith VView Answer on Stackoverflow
Solution 19 - AngularLeepiansView Answer on Stackoverflow
Solution 20 - AngularVadymView Answer on Stackoverflow