将 Node.js 设置为 $PATH
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13203335/
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
Set Node.js to $PATH
提问by Apollo
I am studying RoR and I am setting this virtual machine to "deploy" RoR and I got stuck in the Node.js installation.
我正在研究 RoR,我正在将此虚拟机设置为“部署”RoR,但我在 Node.js 安装中陷入困境。
I am using Ubuntu 12.04 and I followed this step of this guide:
我使用的是 Ubuntu 12.04,我遵循了本指南的这一步:
http://railsapps.github.com/installing-rails.html
http://railsapps.github.com/installing-rails.html
Since Rails 3.1, a JavaScript runtime has been needed for development on Ubuntu Linux (it is not needed for Mac OS X or Windows). For development on Linux Ubuntu, it is best to install the Node.js server-side JavaScript environment:
$ sudo apt-get install nodejsand set it in your $PATH.
从 Rails 3.1 开始,在 Ubuntu Linux 上开发需要一个 JavaScript 运行时(Mac OS X 或 Windows 不需要它)。在 Linux Ubuntu 上开发,最好安装 Node.js 服务器端 JavaScript 环境:
$ sudo apt-get install nodejs并将其设置在您的 $PATH 中。
What does it mean, "set to my $PATH"?
“设置为我的 $PATH”是什么意思?
I've been searching for it on google in the last couple of hours and all solutions are different, for different problems and I get no simple answer for that. Can you give a little light here?
在过去的几个小时里,我一直在谷歌上搜索它,所有解决方案都不同,针对不同的问题,我没有得到简单的答案。你能在这里给点光吗?
Thanks!
谢谢!
回答by mihai
You don't have to worry about that, the apt-get installcommand will do that for you.
It adds the path to the nodejs process (usually /usr/bin/node) to the global $PATH variable. This ensures that when you type nodein your terminal it will start the nodejs process.
你不必担心,apt-get install命令会为你做这件事。它将 nodejs 进程的路径(通常是/usr/bin/node)添加到全局 $PATH 变量中。这确保当您node在终端中输入时,它将启动 nodejs 进程。
If for some weird reason you cannot start it, you'll have to manually add the path to your node installation to the $PATH. You can do this by editing your ~/.bashrcfile and adding:
如果由于某种奇怪的原因无法启动它,则必须手动将节点安装的路径添加到 $PATH。您可以通过编辑~/.bashrc文件并添加:
PATH=/usr/bin/node:$PATH
回答by Vaughany
I've been trying to install npmand it has complained about nodenot being in the path. Funnily enough, nodejswas, but nodewasn't. I ended up solving the problem thus:
我一直在尝试安装npm,但它抱怨node不在路径中。有趣的是,nodejs是,但node不是。我最终解决了这个问题:
$ cd /usr/bin/
$ sudo ln -s nodejs node
...which symlinks nodeto nodejs. Now npminstalls without complaints.
...符号链接node到nodejs. 现在npm安装没有投诉。
回答by Rob Raisch
Depending on which shell you are running, the answer may be different, but a good starting place might be http://www.troubleshooters.com/linux/prepostpath.htm
根据您运行的 shell,答案可能会有所不同,但一个好的起点可能是http://www.troubleshooters.com/linux/prepostpath.htm

