ucimo
ucimo

Reputation: 125

Can't update Angular CLI

As you can see, I have version 9 installed regularly.

npm install -g @angular/cli
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
/home/user/.npm-global/bin/ng -> /home/user/.npm-global/lib/node_modules/@angular/cli/bin/ng

> @angular/[email protected] postinstall /home/user/.npm-global/lib/node_modules/@angular/cli
> node ./bin/postinstall/script.js

+ @angular/[email protected]
updated 1 package in 8.412s

┌─────────────────────────────────────────────────────────┐
│                 npm update check failed                 │
│           Try running with sudo or get access           │
│          to the local update config store via           │
│ sudo chown -R $USER:$(id -gn $USER) /home/user/.config  │
└─────────────────────────────────────────────────────────┘
user@computer:~$ npm list -g
/home/user/.npm-global/lib
├─┬ @angular/[email protected]

But when ever I create new app with 'ng new app-name' I get version 8 installed. When I check for the version with 'ng --version' it says that v8 is installed.

ng --version    

Angular CLI: 8.0.3
Node: 12.16.2
OS: linux x64
Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.800.3
@angular-devkit/core         8.0.3
@angular-devkit/schematics   8.0.3
@schematics/angular          8.0.3
@schematics/update           0.800.3
rxjs                         6.4.0

Can anyone help me?

Upvotes: 4

Views: 3737

Answers (3)

Lothre1
Lothre1

Reputation: 3853

Note for nvm users:

If prior to nvm installation you had @angular/cli globally installed and you are now using a different node version which you installed through nvm, then you might find the notes below useful:

When you switch your node version through nvm the npm folder location where your global node_modules are installed.

Let's say I switched to node 14 (nvm use 14) and installed the latest angular cli using:

npm install @angular/cli -g

You will see an output telling you that angular was successfully installed. Then you run ng --version to verify the version and you realize the old version is still there. Why?

NVM's node is located at: /Users/<USER_NAME>/.nvm/versions/node/v14.XX.XX/bin

After install @angular/cli globally a ng shortcut/symlink is placed inside this folder.

lrwxr-xr-x  1 X  staff        39 14 Ago 10:45 ng -> ../lib/node_modules/@angular/cli/bin/ng
-rwxr-xr-x  1 X  staff  76198080 11 Ago 06:29 node
lrwxr-xr-x  1 X  staff        38 14 Ago 10:42 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxr-xr-x  1 X  staff        38 14 Ago 10:42 npx -> ../lib/node_modules/npm/bin/npx-cli.js

So, it points to the node 14 node_modules folder which is located at: /Users/<USER_NAME>/.nvm/versions/node/v14.XX.XX/lib/node_modules

But since I had @angular/cli installed globally prior to nvm installation, the old version is getting on the way

To fix this, you must find where global node_modules were installed prior to NVM installation. In my case the path is: /usr/local/lib/node_modules.

Go to the folder and remove the @angular. Restart your terminal and run ng --version. You should now get the correct ng version.

This applies to other modules too.

Upvotes: 15

ucimo
ucimo

Reputation: 125

So I uninstalled nodejs and npm and reinstalled them with nvm. I ended with no other choice but to run sudo chown -R $USER:$(id -gn $USER) /home/user/.config and risk affecting my projects. Luckily everything was fine. Than I had an issue with nvm settings not being persistent, but I fixed it with this advice.

Upvotes: 0

400_bad_request
400_bad_request

Reputation: 121

Your user does not have access to write the angular cli directory. The solution is suggested by npm in your terminal, run this command and see if your problem goes away.

   sudo chown -R $USER:$(id -gn $USER) /home/user/.config

Upvotes: 1

Related Questions