In order to fix Error: EACCES: permission denied, access '/usr/lib/node_modules', a solution will be set installed path non-root. Here’s how to set it.

1
2
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'

This can see if config set properly

1
npm config list

Output will be like this

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.14.15 node/v14.18.1 linux x64"

; userconfig /home/wesley/.npmrc
prefix = "/home/wesley/.npm-global"

; node bin location = /usr/local/bin/node
; cwd = /mnt/c/Users/Wesley/GitHub/wesleych3n.github.io/_posts
; HOME = /home/wesley
; "npm config ls -l" to show all defaults.

Add bin path to $PATH variable

1
2
3
if [ -d $HOME/.npm-global ]; then
  export PATH=$HOME/.npm-global/bin:$PATH
fi