已安装 Node.js 但无法通过命令提示符找到文件

Installed Node.js but File Cannot be Found by Command Prompt

我在我的 Raspberry Pi 上安装了 node.js,它是 Raspbian Stretch 上的 运行。

为了安装,我使用了命令$ sudo apt-get install -y nodejs。安装没有问题。

当我尝试通过在命令提示符中键入 $ nodejs -v 来测试安装时,它 returns

nodejs: command not found

如果我再次尝试安装,提示returns

nodejs is already the newest version (8.11.1~dfsg-2~bpo9+1)

此外,当我查看 /usr/bin 文件夹时,我看到 node.js 在那里。

我花了一段时间寻找可能导致此问题的原因,但无济于事。我认为 node.js 文件可能位于错误的文件夹中,但我读过的教程中的 none 有一个步骤可以移动文件。

如能帮助 node.js 正常工作,我们将不胜感激! :)

试试这个:

第 1 步:此命令更新我们的 Debian apt 包存储库以包含 NodeSource 包。

$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

第 2 步:安装 NodeJS(这将确保您安装的是最新版本)

sudo apt install -y nodejs

第 3 步:在 RaspberryPi 中享受 NODEJS

$ node -v
v10.6.0
$ node
> 1 + 3
4
> # We can hit Ctrl-C twice to exit the REPL and get back to the bash (shell) prompt.

如果您与以前的 NODE 安装有冲突,请执行此操作以删除所有现有安装:

运行 which node 会 return 类似 /path/bin/node

然后运行cd /path

然后运行rm -r bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node.1

希望对您有所帮助!