简体   繁体   中英

Unable to install npm packages

I have to install npm package hence used command - npm install -g <package-name> but it resulted into write access error so I changed permissions as follows with refernce to https://flaviocopes.com/npm-fix-missing-write-access-error/

sudo chown -R $USER /opt/node-v10.22.0-linux-x64/lib/node_modules/

and tried again but if failed again -

npm ERR! code EACCES
npm ERR! syscall symlink
npm ERR! path ../lib/node_modules/requirejs/bin/r.js
npm ERR! dest /opt/node-v10.22.0-linux-x64/bin/r.js
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/requirejs/bin/r.js' -> '/opt/node-v10.22.0-linux-x64/bin/r.js'
npm ERR!  { [Error: EACCES: permission denied, symlink '../lib/node_modules/requirejs/bin/r.js' -> '/opt/node-v10.22.0-linux-x64/bin/r.js']
npm ERR!   cause:
npm ERR!    { Error: EACCES: permission denied, symlink '../lib/node_modules/requirejs/bin/r.js' -> '/opt/node-v10.22.0-linux-x64/bin/r.js'
npm ERR!      errno: -13,
npm ERR!      code: 'EACCES',
npm ERR!      syscall: 'symlink',
npm ERR!      path: '../lib/node_modules/requirejs/bin/r.js',
npm ERR!      dest: '/opt/node-v10.22.0-linux-x64/bin/r.js' },
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, symlink \'../lib/node_modules/requirejs/bin/r.js\' -> \'/opt/node-v10.22.0-linux-x64/bin/r.js\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'symlink',
npm ERR!   path: '../lib/node_modules/requirejs/bin/r.js',
npm ERR!   dest: '/opt/node-v10.22.0-linux-x64/bin/r.js' }
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.

also when I run command with sudo , it gives npm not found . Please guide what is wrong here.

you need read write permissions to /opt/node-v10.22.0-linux-x64/ as it creates a symlink there for you. you can also check the destination in error it clearly says you don't have permission there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM