Upgrading global Angular cli version?

Issue

When I inquire about the @angular/cli version through npm, it tells me it’s version

npm list -g --depth=0 @angular/cli
>>> @angular/cli@8.3.21

But when I inquire via ng --version, it tells me it’s 8.0.0-beta.11. I’m not in a local angular project. I can’t figure out how to thoroughly upgrade my global ng. Suggestions?

Edit: Here’s some extra info as requested in comments:

sw_vers -productVersion # Show Mac OSX version
>>> 10.15.2

which -a ng
>>> /Users/magnus/.nvm/versions/node/v10.16.3/bin/ng
>>> /usr/local/bin/ng

/Users/magnus/.nvm/versions/node/v10.16.3/bin/ng --version
>>> ... Angular CLI: 8.0.0-beta.11 ...

/usr/local/bin/ng --version
>>> ... Angular CLI: 8.0.0-beta.11 ...
realpath /usr/local/bin/ng
>>> /usr/local/lib/node_modules/@angular/cli/bin/ng

cat ~/.npmrc
>>> ignore-scripts=false

I installed npm via nvm with the intention to only use that version. Not sure why I am seeing an ng executable in /usr/local/bin; I’m pretty sure I wouldn’t have tried installed it via homebrew.

Solution

OK, in my case the problem was that I had two npm installs on my Mac (one via homebrew and one via nvm). Despite that the nvm install of npm had priority in my $PATH, the version of ng that got priority was the one installed via the homebrew install of npm. So any effort I made to update/reinstall/etc the angular client using the nvm install of npm was having no effect on the version of the cli installed by the homebrew install of npm. (And even if I used the full path to ng as installed by the nvm version of npm, it was was somehow eventually always linking through to the version of ng installed by the homebrew install of npm.)

My solution was to just get rid of the homebrew install of npm and all its packages. The key here is to first use the full path to the homebrew install of npm to remove all global packages (e.g. /usr/local/bin/npm remove -g @angular/cli), and then to remove the homebrew install of npm itself (brew remove npm).

Now there is only the nvm install of npm in my path, and I was able to get the latest global install of the angular cli using npm install -g @angular/cli@next.

Answered By – Magnus

Answer Checked By – Marie Seifert (AngularFixing Admin)

Leave a Reply

Your email address will not be published.