Blog.

Npm permission issue

Got a Issue when installing npm package in global mode, state that permission denied.

Make some research, and found this https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

Potential fix:

  1. add current user to root group. work years ago. but dangerous to handle with permission
  2. use hidden directory in your home directory. manual change npm directory, may corrupt the npm.
  3. use nvm and install desired node version. Easy to maintain

Final fix: uninstall current npm and nodejs and install nvm

1. Check currently install global package

list all top level global package

$ sudo npm list -g --depth=0

2. Remove All Top level global package

$ sudo npm list -g --depth=0 | awk -F ' ' '{print $2}' | awk -F '@' '{print $1}'  | sudo xargs npm remove -g

3. Install Node Version Manager

follow nvm instruction from github.com/creationix/nvm

then nvm should have been installed to ~/.nvm and source line to my profile.

But in my case using zsh. I can only see the source line adding to .bashrc but not .zshrc

so need to add following lines to .zshrc.

But after digging goole. There's a better the method to add source line by adding nvm to .zshrc plugin session.

 plugins=(git docker docker-compose zsh-autosuggestions nvm)

4. Renstall Nodejs and npm

then install npm with latest version

 $ nvm install node

or specified version

$ nvm install 12.10

5. Verify for the installation

$ npm -v
$ node -v

More Stories

Nginx for react router spa

Nginx for react router spa

nginx settings on react spa

CSRF attack and solution

CSRF attack and solution

CSRF attack and solution