node.jsubuntunpmvpsnvs

permission denied when I do "npm install" in Ubuntu


I have a new VPS with Ubuntu installed, just clone my repo inside /var/www and when I tried to do npm install it says: Error: EACCES: permission denied, mkdir

Also when doing sudo npm install I'm getting sudo: npm: command not found

I installed npm using nvm latest version.

When I do whereis node and whereis npm I get /home/myuser/.nvm/versions/node/v.21.7.1/bin. I dont really know if this is correct path as I tried to remove all node and nvm and It is installing in the same place.

I have seen some solutions suggest upgrading the permissions with sumo chown but I think that is not the right approach.

Hope someone can help!!


Solution

  • /var/www is protected so you have either to: