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

问题描述 投票:0回答:1

我正在尝试通过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。我正在将root用户和ssh密钥文件一起使用。
我正在尝试通过node-ssh做一些自动化脚本,但是它的行为很奇怪:当我使用经典ssh(通过终端或vs代码)时,节点版本是10.16.3,而NVM命令是...] >
node.js ssh virtual-machine nvm
1个回答
0
投票
我已找出问题所在:https://www.digitalocean.com/community/questions/node-v-and-nodejs-v-different-output

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

© www.soinside.com 2019 - 2024. All rights reserved.