Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to install npm package || permission denied

I am getting the following error while installing PM2. I have also tried installing it locally but nothing seems to be working. please help.

Command:npm install pm2 -g

anil@anil:~/Desktop/restapis$ npm install pm2 -g 
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/pm2/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! Linux 4.4.0-78-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "pm2" "-g"
npm ERR! node v6.10.3
npm ERR! npm  v3.10.10
npm ERR! path ../lib/node_modules/pm2/bin/pm2
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall symlink

npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/pm2/bin/pm2' -> '/usr/local/bin/pm2'
npm ERR!     at Error (native)
npm ERR!  { Error: EACCES: permission denied, symlink '../lib/node_modules/pm2/bin/pm2' -> '/usr/local/bin/pm2'
npm ERR!     at Error (native)
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'symlink',
npm ERR!   path: '../lib/node_modules/pm2/bin/pm2',
npm ERR!   dest: '/usr/local/bin/pm2' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/anil/Desktop/restapis/npm-debug.log
anil@anil:~/Desktop/restapis$ ^C
anil@anil:~/Desktop/restapis$ sudo chmod 777 /lib/node_modules/pm2/bin/pm2
chmod: cannot access '/lib/node_modules/pm2/bin/pm2': No such file or directory
anil@anil:~/Desktop/restapis$ x
like image 697
Anil Sharma Avatar asked May 25 '17 12:05

Anil Sharma


Video Answer


1 Answers

You are trying to instal PM2 as /usr/local/bin/pm2 and you need root access for that.

Instead of:

npm install pm2 -g 

you need:

sudo npm install pm2 -g

Note that you need to be in the sudoers group.

Alternatively you can install Node in your home directory instead of system-wide and then you won't need sudo for install -g

like image 147
rsp Avatar answered Nov 07 '22 05:11

rsp