在共享主机上使用带位桶管道的ssh时找不到npm命令 [英] npm command is not found when ssh with bitbucket pipelines on shared hosting
问题描述
我已经按照此处.
我自己SSH到服务器时,一切正常.但是我创建了一个脚本,用于部署我的应用程序并通过位桶管道调用它.除npm install
之外,其他所有东西都可以正常工作(composer install
,php artisan migrate
等).错误消息是
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:第26行:npm:未找到命令
./deploy: line 26: npm: command not found
在bitbucket-pipelines.yml中,我这样称呼我的脚本:
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 :(.
推荐答案
正在运行which composer
显示至少没有从您的假定位置(即~/composer
)拾取composer
命令.目录相反,它是在/opt/cpanel/composer/bin/composer
中找到的.
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
返回以下内容:
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)
现在,由于您能够手动运行命令npm
,因此您只需要弄清npm
的运行路径,并确保该路径已明确地添加到用户的 ~/.bashrc
文件,一切正常.您需要执行此操作,因为根据您的观察,ssh
无法找到它.
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
注意:为避免混淆,只需记住在将路径添加到二进制文件时,只需将路径添加到npm
所在的目录即可.不要在末尾添加npm
.例如,以下是不正确的方式:
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
正确的方法是这样:
export PATH=$PATH:/home/handmast/bin
这篇关于在共享主机上使用带位桶管道的ssh时找不到npm命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!