node.js 节点:找不到命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13593902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:43:50  来源:igfitidea点击:

node: command not found

node.js

提问by Alex Getty

I am in the process of setting up node.js in order to work with a framework like Meteor, Derby, or Ember, but am running into some problems early on. Following these instructions (http://www.nodebeginner.org), I installed node, created a simple helloworld.js file, then ran this command in the terminal:

我正在设置 node.js 以便与 Meteor、Derby 或 Ember 等框架一起使用,但在早期遇到了一些问题。按照这些说明 (http://www.nodebeginner.org),我安装了 node,创建了一个简单的 helloworld.js 文件,然后在终端中运行这个命令:

node path/to/file/helloworld.js

but I get the following error:

但我收到以下错误:

-bash: node: command not found

I've tried navigating to the directory, then simply running:

我试过导航到目录,然后简单地运行:

node helloworld.js

but get the same error. I am completely new to node.js and am at a loss.

但得到同样的错误。我对 node.js 完全陌生并且不知所措。

Running OS X 10.7.5 and the latest version of node.

运行 OS X 10.7.5 和最新版本的节点。

回答by maerics

The problem is that your PATH does not include the location of the node executable.

问题是您的 PATH 不包含节点可执行文件的位置。

You can likely run node as "/usr/local/bin/node".

您可能可以将节点运行为“ /usr/local/bin/node”。

You can add that location to your path by running the following command to add a single line to your bashrc file:

您可以通过运行以下命令将该位置添加到您的路径中,以在您的 bashrc 文件中添加一行:

echo 'export PATH=$PATH:/usr/local/bin' >> $HOME/.bashrc