Global packages go to a folder owned by root
CommonNode.js from a system package or an installer puts the global prefix somewhere like /usr/local, which a normal account cannot write.
Confirm
npm prefix -g; ls -ld "$(npm prefix -g)/lib"
A prefix such as /usr/local whose lib folder is owned by root
Fix
- Best, according to npm's documentation: install Node.js with a node version manager, which keeps Node, npm and global packages in your home folder.
- Or move the global folder to one you own: npm config set prefix ~/.local, then add PATH=~/.local/bin:$PATH to ~/.profile and open a new shell.
- For project tools, skip the global install: npm install --save-dev the tool and run it with npx.