node.js - 在共享主机上使用 bitbucket 管道进行 ssh 时找不到 npm 命令

标签 node.js ssh bitbucket bitbucket-pipelines

我已经按照描述安装了nodejs here

当我自己 ssh 到服务器时一切正常。但我创建了一个脚本来部署我的应用程序并通过 bitbucket 管道调用它。除了 npm install 之外,其他一切都工作正常(composer installphp artisan migrate 等)。错误信息是

./deploy: line 26: npm: command not found

在 bitbucket-pipelines.yml 中,我这样调用我的脚本:

- step:
    script:
      - ssh user@ip_address ./deploy

当我自己调用脚本时,一切正常。问题仅出在 bitbucket 管道上。我不知道为什么会发生这种情况:(。

最佳答案

运行whichcomposer显示至少composer命令没有从您的假定位置(即~/composer目录)中获取。相反,它是在 /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 无法找到它。

export PATH=$PATH:/path/to/npm/binary

注意:为了避免任何混淆,请记住,在添加二进制文件的路径时,您只需将路径添加到 npm 所在的目录即可。不要在末尾添加 npm。例如,以下是不正确的方式:

export PATH=$PATH:/home/handmast/bin/npm

正确的方法是这样的:

export PATH=$PATH:/home/handmast/bin

关于node.js - 在共享主机上使用 bitbucket 管道进行 ssh 时找不到 npm 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57643659/

相关文章:

javascript - 为什么结果是 global name ,这是由 "this"引起的吗?

node.js - 从 Node.js 脚本中读取 npm 配置值

node.js - 无服务器出站流量保护

php - 使用 sftp 和 ssh2 的 fopen 段错误

node.js - Bitbucket 管道运行 npm 失败

git - 在 BitBucket SourceTree 中 checkout 、获取和 pull

git push 提交到不同的分支

php - Node.js API 与 express 和 mysql - 仅在设置时应用搜索参数

shell - 使用打包程序将文件从主机复制到生成的图像而无需密码

ubuntu - git remote : Invalid username or password. 致命:身份验证失败 - ubuntu