Npm command not found after launch build.sh file

1.5k views Asked by At

I installed nvm and then installed npm by nvm install npm.
Nvm and npm have been installed to my main directory ~/.nvm and ~/.npm. And yes, npm command is correct in every directory in the server on the ssh connection in console.
I added also build.sh file where I wrote npm run prod command and added this in post-receive git hook.

BUT! When I send new commits to this server, I see in console note like "npm command not found". WHY????
After all, on the server everything is okay!

I tried also move ~/.npm to /usr/local/bin/ but it wasn't help. Probably because .npm it is a folder. I don't know...
I solved problem by deleting .nvm and .npm folders and installing npm through sudo apt-get. I guess it automatically have added needs files in needs directories to make npm command globally available.

In spite of I solved the problem by another way, I want to know what I was doing incorrectly in the first approach, cause maybe in the future I need nvm. Can someone experienced in linux explain me what the problem was?

1

There are 1 answers

0
Reynaldo Aceves On

Make sure the absolute path where npm command was installed is listen within your PATH variable, then make sure you export this variable so your build.sh script can see the new value and search for npm binary.

echo $PATH
export PATH="/path/to/my/installation/:$PATH"
echo $PATH
./build.sh