pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

Can't install PM2 node

Open StefCoders opened this issue 2 years ago • 2 comments

What's going wrong?

I cannot install PM2 (i am root).

How could we reproduce this issue?

I'm really not sure, I was installing shinobi and said PM2 - command not found

Supporting information

$ pm2 report
pi@raspberrypi:~ $ sudo npm i -g pm2
npm ERR! code EACCES
npm ERR! syscall connect
npm ERR! errno EACCES
npm ERR! FetchError: request to https://registry.npmjs.org/pm2 failed, reason: connect EACCES 2606:4700::6810:1f22:443
npm ERR!     at ClientRequest.<anonymous> (/usr/share/nodejs/minipass-fetch/lib/index.js:130:14)
npm ERR!     at ClientRequest.emit (node:events:513:28)
npm ERR!     at TLSSocket.socketErrorListener (node:_http_client:496:9)
npm ERR!     at TLSSocket.emit (node:events:525:35)
npm ERR!     at emitErrorNT (node:internal/streams/destroy:151:8)
npm ERR!     at emitErrorCloseNT (node:internal/streams/destroy:116:3)
npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
npm ERR!  FetchError: request to https://registry.npmjs.org/pm2 failed, reason: connect EACCES 2606:4700::6810:1f22:443
npm ERR!     at ClientRequest.<anonymous> (/usr/share/nodejs/minipass-fetch/lib/index.js:130:14)
npm ERR!     at ClientRequest.emit (node:events:513:28)
npm ERR!     at TLSSocket.socketErrorListener (node:_http_client:496:9)
npm ERR!     at TLSSocket.emit (node:events:525:35)
npm ERR!     at emitErrorNT (node:internal/streams/destroy:151:8)
npm ERR!     at emitErrorCloseNT (node:internal/streams/destroy:116:3)
npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
npm ERR!   code: 'EACCES',
npm ERR!   errno: 'EACCES',
npm ERR!   syscall: 'connect',
npm ERR!   address: '2606:4700::6810:1f22',
npm ERR!   port: 443,
npm ERR!   type: 'system',
npm ERR!   requiredBy: '.'
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-10-15T18_30_12_442Z-debug-0.log

pi@raspberrypi:~ $ sudo npm i -g pm2
npm ERR! code EACCES
npm ERR! syscall connect
npm ERR! errno EACCES
npm ERR! FetchError: request to https://registry.npmjs.org/pm2 failed, reason: connect EACCES 2606:4700::6810:1f22:443
npm ERR!     at ClientRequest.<anonymous> (/usr/share/nodejs/minipass-fetch/lib/index.js:130:14)
npm ERR!     at ClientRequest.emit (node:events:513:28)
npm ERR!     at TLSSocket.socketErrorListener (node:_http_client:496:9)
npm ERR!     at TLSSocket.emit (node:events:525:35)
npm ERR!     at emitErrorNT (node:internal/streams/destroy:151:8)
npm ERR!     at emitErrorCloseNT (node:internal/streams/destroy:116:3)
npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
npm ERR!  FetchError: request to https://registry.npmjs.org/pm2 failed, reason: connect EACCES 2606:4700::6810:1f22:443
npm ERR!     at ClientRequest.<anonymous> (/usr/share/nodejs/minipass-fetch/lib/index.js:130:14)
npm ERR!     at ClientRequest.emit (node:events:513:28)
npm ERR!     at TLSSocket.socketErrorListener (node:_http_client:496:9)
npm ERR!     at TLSSocket.emit (node:events:525:35)
npm ERR!     at emitErrorNT (node:internal/streams/destroy:151:8)
npm ERR!     at emitErrorCloseNT (node:internal/streams/destroy:116:3)
npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
npm ERR!   code: 'EACCES',
npm ERR!   errno: 'EACCES',
npm ERR!   syscall: 'connect',
npm ERR!   address: '2606:4700::6810:1f22',
npm ERR!   port: 443,
npm ERR!   type: 'system',
npm ERR!   requiredBy: '.'
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-10-15T18_30_12_442Z-debug-0.log

StefCoders avatar Oct 15 '23 18:10 StefCoders

Hi @StefCoders, your problem is interesting.

Please send details: a. Raspberry version b. Operating System c. Log file generated at finished execution. Example: 2023-10-15T18_30_12_442Z-debug-0.log

For now, try the procedure below. Change the location where global packages are stored, so you don't need superuser privileges:

a. Create a directory for global npm packages in your home directory: $ mkdir ~/.npm-global

b. Configure npm to use this directory for global packages: $ npm config set prefix '~/.npm-global'

c. Add the following line to your shell profile (e.g., ~/.bashrc or ~/.zshrc): $ export PATH = ~/.npm-global/bin:$PATH

d. Source your shell profile to apply the changes: $ source ~/.bashrc

e. Now you should be able to install npm packages globally without using sudo: $ npm install -g pm2

Please give feedback. Regards

danielrpgj31 avatar Oct 16 '23 10:10 danielrpgj31

@danielrpgj31 It helped, thanks a lot!

Small correction: it should not have spaces between key and value export PATH = ~/.npm-global/bin:$PATH causes this error: -bash: export: =': not a valid identifier`

correct command: export PATH=~/.npm-global/bin:$PATH

BzenkoSergey avatar May 07 '24 18:05 BzenkoSergey