【问题标题】:I have different versions of node js (and lot of other things) in shell and node-ssh我在 shell 和 node-ssh 中有不同版本的 node js(以及许多其他东西)
【发布时间】:2019-12-07 16:00:16
【问题描述】:

我正在尝试通过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%s\x1b[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 密钥文件的 root 用户。

【问题讨论】:

    标签: node.js ssh virtual-machine nvm


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-25
      • 2011-11-18
      • 2022-08-12
      • 1970-01-01
      • 2021-10-31
      相关资源
      最近更新 更多