npm not found error in jenkins pipeline job

Viewed 2875

I have a pipeline job, where I give npm install. The script goes like :

node {
    stage('Configure repo') {
        sh 'npm install'
    }
}

I am getting error

/mnt/jenkins/workspace/project/proj/dura/script.sh: 2: /mnt/jenkins/workspace/project/proj/dura/script.sh: /usr/local/npm: not found

Even I tried giving sh '/usr/local/npm install' But still the same.

Please help

1 Answers

Run this command:

sudo -u jenkins which npm

You should see /usr/bin/npm or some other path to npm as the result. if not, run this command:

sudo apt install npm

This often happens when you don't specifically install npm after installing node. Because node installs an instance of npm in your home, which other user's will not have access to. Then you feel you already installed npm but the fact is, you didn't!

Related