乡民篇-Github actions bash: npm: command not found when on ssh

前言

我想用GitHub actions去做CI/CD,主要做的事情很简单,只有gut push和npm install,但却不尽人意,在actions读取到执行npm install的时候,会出现npm command not found,我想原因是出在我的VPS设定上面,我们就一起来看下面解Bug的过程吧。

环境:Ubuntu 18.04.4 LTS (GNU/Linux 5.3.0-1026-gcp x86_64)

本系列目标

本系列所分享的bug实在太雷所以分2篇写解法,分别是我在网路上找到乡民写的类似问题的解法,以及后期我自行去挖掘真相后自己的解法

(本篇) 乡民篇-Github actions bash: npm: command not found when on ssh真相篇-Github actions bash: npm: command not found when on ssh

本篇参考乡民解法:

https://github.com/animetosho/Nyuu/issues/14

step1. 查询环就变数which npm就会拿到npm的绝对路
$ which npm

which指令会在环境变量$PATH设置的目录里查找符合条件的文件。所以echo $PATH也可以从~/.bashrc环境变数中拿到一样的绝对路径

step2. 新错误讯息
/usr/bin/env: ‘node’: No such file or directory

原因是因为在OS上Debian呼叫"nodejs"替代"node",而Ubuntu相反,所以我们在VPS下指令做软连结让nodejs=node

step3
$ ln -s /usr/bin/nodejs /usr/bin/node

得到同样错误讯息:

/usr/bin/env: ‘node’: No such file or directory
step4. 在VPS上重新安装node
$ sudo apt-get install nodejs-legacy

跑出错误讯息:

Reading package lists... DoneBuilding dependency treeReading state information... DonePackage nodejs-legacy is not available, but is referred to by another package.This may mean that the package is missing, has been obsoleted, oris only available from another sourceHowever the following packages replace it:  nodejsE: Package 'nodejs-legacy' has no installation candidate

提示我们把nodejs-legacy改成nodejs

step4. 我们重新下指令
sudo apt-get install nodejs

成功

以下是我们修改好的yml档案:

name: CIon: [push]jobs:  build:    runs-on: self-hosted    strategy:      matrix:        node-version: [10.15.3]    steps:    - uses: actions/checkout@v2    - name: decrypt      run: |        gpg --quiet --batch --yes --decrypt --passphrase="$PASSPHRASE" \        --output $HOME/secrets/key google_compute_engine.gpg      env:        PASSPHRASE: ${{ secrets.PASSPHRASE }}    - name: chmod      run: chmod 600 $HOME/secrets/key    - name: ssh      run: ssh -o StrictHostKeyChecking=no -i $HOME/secrets/key zen_master@35.187.152.88 "cd postmark-side-project/;git pull;sudo /home/zen_master/.nvm/versions/node/v10.15.3/bin/npm install"

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章