我在shell和node-ssh中有不同的Node js版本(以及许多其他东西)



我正在尝试通过node-ssh执行一些自动化脚本,但它的行为方式非常奇怪:

当我使用经典的ssh(通过终端或vs代码(节点版本为10.16.3并且NVM命令可用时:

node --version 
v10.16.3

但是当我使用库node-ssh和命令execCommand时,节点版本似乎是8.10.0,NVM命令不可用:

import node_ssh from 'node-ssh';
const command = 'node --version';
const client = new node_ssh();
await client.connect(sshCredentials);
console.log('x1b[36m%sx1b[0m', command, 'x1b[0m');
client.execCommand(command , { cwd: remoteDir });
console.log(result.stdout);
node --version 
v8.10.0

此外,环境变量也不同。我不知道这里发生了什么。我正在使用同一台服务器和同一台计算机,该计算机通过ssh连接到该服务器上,具有相同密钥文件的相同用户,但它的行为不同。

服务器位于DigitalOcean上。 它是Ubuntu 18.04.3 LTS。 我正在使用带有 ssh 密钥文件的根用户。

我已经解决了问题: https://www.digitalocean.com/community/questions/node-v-and-nodejs-v-different-output

这可以通过安装 node.js 从官方 Ubuntu 软件包而不是通过 NVM 来解决。 https://github.com/nodesource/distributions#debinstall

相关内容

最新更新