Can't install pm2 - failed to run installation scripts bash: npm: command not found

fwconsole ma downloadinstall pm2
No repos specified, using: [standard,extended] from last GUI settings

Downloading module ‘pm2’
Processing pm2
Verifying local module download…Verified
Download completed in 6 seconds
Installing/Updating Required Libraries. This may take a while…The following messages are ONLY FOR DEBUGGING. Ignore anything that says ‘WARN’ or is just a warning
Running installation…
bash: npm: command not found

Finished updating libraries!

There was an error installing. Please review the install log. (/var/www/html/admin/modules/pm2/node/logs/install.log)
Unable to install module pm2:

  • Failed to run installation scripts
    Updating Hooks…Done
    Chowning directories…Done

npm and nodejs are all installed. I can run npm from the cl
I’ve been fighting this for a while - seems like it may be a bash issue? Just incase, here is my .bashrc file:

export NVM_DIR=“$HOME/.nvm”
[ -s “$NVM_DIR/” ] && . “$NVM_DIR/” # This loads nvm
[ -s “$NVM_DIR/bash_completion” ] && . “$NVM_DIR/bash_completion” # This load$

User specific aliases and functions

alias rm=‘rm -i’
alias cp=‘cp -i’
alias mv=‘mv -i’

Source global definitions

if [ -f /etc/bashrc ]; then
. /etc/bashrc

Ok … figured a couple of things out.

su asterisk -c “npm -v”

Gives me the same “bash: npm: command not found” – error.

So it seems to be an issue with how nodejs was installed – which nodejs always seems to install into the user’s home directory (which at the time - I ran as root).
The command:

ls -l $(which npm)

Gives me:
/root/.nvm/versions/node/v15.14.0/bin/npm → …/lib/node_modules/npm/bin/npm-cli.js

So do I need to remove nodejs and then reinstall it as user asterisk?

you don’t necessarily need to uninstall it but you made a good call, asterisk can’t find it, how are you installing it ? system wide installation would putit in /usr/bin

Should I install Node.js 8 for compatibility … or install what they recommend - version 14?

I can’t answer that authoritatively for Centos, my installs are happy at 10 or 11, 12 and up breaks shit.

Ok …finally got it going. Thank you for your help dicko.

Apparently I used the wrong tutorial/guide to install Node.js (it had me install nvm manager to then install npm & node - which put everything under the root home directory). Got it removed and installed node as per the instructions from the wiki ( I did update it to ver 10 though.

Once this was all fixed I was able to install pm2 and upgrade all the other modules.

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.