问题
I've installed nodejs as described here.
Everything works fine when I ssh to the server myself. But I've created a script that deploys my application and call it via bitbucket pipelines. Everything else works fine (composer install
, php artisan migrate
etc.), except npm install
. The error message is
./deploy: line 26: npm: command not found
In bitbucket-pipelines.yml I call my script like this:
- step:
script:
- ssh user@ip_address ./deploy
When I call the script by myself everything works. The problem is only with bitbucket pipelines. I have no clue why this happens :(.
回答1:
Running which composer
revealed that at least composer
command is not getting picked up from your assumed location i.e., ~/composer
dir. Instead, it was found in /opt/cpanel/composer/bin/composer
.
which npm
returned the following:
no npm in (/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin:/opt/bin:/opt/cpanel/composer/bin:/home/handmast/.local/bin:/home/handmast/bin)
Now since you are able to manually run the command npm
, you just need to figure about the path from where npm
is running and ensure that the path is explicitly added to the user's ~/.bashrc
file and things should work fine. You need to do this because as per your observation, ssh
is not able to find it.
export PATH=$PATH:/path/to/npm/binary
Note: To avoid any confusion, just remember that while adding the path to your binary, you just have to add the path to the directory where npm
resides. Don't add npm
at the end. For example, following is incorrect way:
export PATH=$PATH:/home/handmast/bin/npm
Correct way is this:
export PATH=$PATH:/home/handmast/bin
来源:https://stackoverflow.com/questions/57643659/npm-command-is-not-found-when-ssh-with-bitbucket-pipelines-on-shared-hosting