Nikki Kononov Nikki Kononov - 1 year ago 53
Node.js Question

Can't upgrade NPM packages with npm update/upgrade -g command

Running Archlinux + Gnome-Shell 3.20, NodeJS 5.10.1 NPM 3.8.6 version.

When running

sudo npm update -g
sudo npm upgrade -g
terminal gives

npm ERR! addLocal Could not install /build/semver/src/semver-5.1.0.tgz
npm ERR! addLocal Could not install /build/semver/src/semver-5.1.0.tgz
npm ERR! addLocal Could not install /build/uglify-js/src/uglify-js-2.6.2.tgz

Same output for
sudo npm outdated -g

While running
sudo npm install -g <package_name>
"updates" package no problem. Of course, I could install/upgrade each package individually but that defeats the purpose of npm update/upgrade -g command.

I've updated NPM to latest version via
sudo npm install -g npm@latest

in hopes it would fix the issue like for many here but to no avail.

joe joe

There are a few things that could be wrong, and this should help resolve your problem.

  1. You should fix your npm permissions, so you don't have to use sudo when you attempt to install a package globally using npm.

  2. nvm is a tool that should be able to help you. There is likely an bug/corruption in your current node/npm version by looking at the GitHub issue, and the tool nvm will make it possible to change node versions while also fixing your sudo issue.

It is also possible that you installed npm using pacman rather than npm which could be why you can't upgrade correctly. You could the latest version of npm by using the command pacman -S npm which is a package available in the community repository.