How can I run `npm` on WSL without sudo?

Viewed 716

I am unable to install node packages on WSL without sudo. I have installed node with nvm so as to have the exact version as in the tutorial1 that I am following to create a Flask-Vue application.

I am trying to install Vue with the following command:

npm install -g @vue/cli

and I get the following output:

(env) [souto@server]$ npm install -g @vue/cli
 Unhandled rejection Error: EACCES: permission denied, mkdir '/home/souto/.npm/_cacache/content-v2/sha512/0e/86'

Unhandled rejection Error: EACCES: permission denied, mkdir '/home/souto/.npm/_cacache/content-v2/sha512/5e/0e'

Unhandled rejection Error: EACCES: permission denied, mkdir '/home/souto/.npm/_cacache/content-v2/sha512/0e/98'

npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://npm.community>

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/souto/.npm/_logs/2019-10-21T16_05_57_968Z-debug.log

Complete log available here2, in case it helps:

I have tried to follow the instructions in the accepted answer here: How can I run NPM without sudo? but it seems that doesn't work if I have installed node through nvm:

┌─────────────────────────────────────────────────────────┐
│                 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/souto/.config │
└─────────────────────────────────────────────────────────┘
nvm is not compatible with the npm config "prefix" option: currently set to "/home/souto/npm"
Run `npm config delete prefix` or `nvm use --delete-prefix v12.1.0 --silent` to unset it.

I have tried other things and spent a few hours trying to make this work, and in order not to waste more time I have now moved to try my luck in a linux virtual machine.

I'd be thankful for any help.

0 Answers
Related