Ubuntu npm install Error EACCES permission denied symlink

Error

> npm install -g http-server
npm ERR! path ../lib/node_modules/http-server/bin/http-server
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall symlink
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/http-server/bin/http-server' -> '/usr/bin/http-server'
npm ERR!  { [Error: EACCES: permission denied, symlink '../lib/node_modules/http-server/bin/http-server' -> '/usr/bin/http-server']
npm ERR!   cause:
npm ERR!    { Error: EACCES: permission denied, symlink '../lib/node_modules/http-server/bin/http-server' -> '/usr/bin/http-server'
npm ERR!      errno: -13,
npm ERR!      code: 'EACCES',
npm ERR!      syscall: 'symlink',
npm ERR!      path: '../lib/node_modules/http-server/bin/http-server',
npm ERR!      dest: '/usr/bin/http-server' },
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, symlink \'../lib/node_modules/http-server/bin/http-server\' -> \'/usr/bin/http-server\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'symlink',
npm ERR!   path: '../lib/node_modules/http-server/bin/http-server',
npm ERR!   dest: '/usr/bin/http-server' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:

Solution

sudo chown -R $(whoami) ~/.npm

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
  •  
  •  
  •  
  •  

Viet Luu has written 276 articles

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

We are thankful for your never ending support.