Home > Back-end >  How do I fix the npm error EACCES: permission denied?
How do I fix the npm error EACCES: permission denied?

Time:10-03

I tried to start a project with installing npm install -g pnpm as a requirement and I tried npm install but it does work. But npm install -g pnpmshows errors as follow; Below is from the terminal!

npm ERR! code EACCES
npm ERR! syscall symlink
npm ERR! path ../lib/node_modules/pnpm/bin/pnpm.cjs
npm ERR! dest /usr/bin/pnpm
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/pnpm/bin/pnpm.cjs' -> '/usr/bin/pnpm'
npm ERR!  [OperationalError: EACCES: permission denied, symlink '../lib/node_modules/pnpm/bin/pnpm.cjs' -> '/usr/bin/pnpm'] {
npm ERR!   cause: [Error: EACCES: permission denied, symlink '../lib/node_modules/pnpm/bin/pnpm.cjs' -> '/usr/bin/pnpm'] {
npm ERR!     errno: -13,
npm ERR!     code: 'EACCES',
npm ERR!     syscall: 'symlink',
npm ERR!     path: '../lib/node_modules/pnpm/bin/pnpm.cjs',
npm ERR!     dest: '/usr/bin/pnpm'
npm ERR!   },
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'symlink',
npm ERR!   path: '../lib/node_modules/pnpm/bin/pnpm.cjs',
npm ERR!   dest: '/usr/bin/pnpm'
npm ERR! }
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.

CodePudding user response:

  1. Back up your computer.

  2. On the command line, in your home directory, create a directory for global installations:

mkdir ~/.npm-global
  1. Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
  1. In your preferred text editor, open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH

  1. On the command line, update your system variables:
source ~/.profile

  1. To test your new configuration, install a package globally without using sudo:
npm install -g pnpm

source : https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

  • Related