2

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

npm install -g @angular/cli
npm WARN deprecated request@2.88.2: 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/cli@9.1.1 postinstall /home/user/.npm-global/lib/node_modules/@angular/cli
> node ./bin/postinstall/script.js

+ @angular/cli@9.1.1
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/cli@9.1.1

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?

ucimo
  • 105
  • 11
  • 1
    **DO NOT post images of code, data, error messages, etc.** - copy or type the text into the question. [ask] – Rob Apr 19 '20 at 13:13
  • I replaced images with err txt. I rarely post here, so I forgot about the rule. Thx @Rob – ucimo Apr 19 '20 at 13:20
  • 2
    Could you try to uninstall Angular CLI with `npm uninstall -g @angular/cli`. After that cleaning the npm cache: `npm cache clean --force`. After that install Angular CLI with `npm install -g @angular/cli` again? – Milan Tenk Apr 19 '20 at 13:40
  • I tried that many times, and again, nothing happens. I even reinstalled nvm, node, npm but ng v8 is still pressent... even though I didn't install it? how is that even possible? – ucimo Apr 19 '20 at 14:11

3 Answers3

6

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.

Lothre1
  • 3,523
  • 7
  • 43
  • 64
1

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
  • I installed nvm just so I don't have to use sudo, and I feel very uneasy to use 'chown' as I'm afraid that might have impact on some of my projects... How could I make sure this will not have effect on them? – ucimo Apr 19 '20 at 14:10
  • 1
    Try these steps if you are nervous about sudo, make sure to keep the code in your home directory so you own it. This is the procedure : https://stackoverflow.com/questions/48910876/error-eacces-permission-denied-access-usr-local-lib-node-modules-react – 400_bad_request Apr 19 '20 at 14:20
0

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.

ucimo
  • 105
  • 11