如何为 nodejs (Ubuntu) 设置节点路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7076529/
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
How to set node path for nodejs (Ubuntu)
提问by Horstus Horax
I'm trying to setup nodejs to access a postgres database. What I've done so far is the following (https://gist.github.com/579814):
我正在尝试设置 nodejs 以访问 postgres 数据库。到目前为止我所做的是以下(https://gist.github.com/579814):
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl http://npmjs.org/install.sh | sh
then
然后
git clone git://github.com/isaacs/npm.git
make
make install
so far, so good. However, when I try to install the postgres driver
到目前为止,一切都很好。但是,当我尝试安装 postgres 驱动程序时
npm install pg
I get the following:
我得到以下信息:
node-waf configure build || true
node-waf 配置构建 || 真的
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : not found
Checking for node prefix : ok /usr/local
Checking for program pg_config : /usr/bin/pg_config
'configure' finished successfully (0.066s)
Waf: Entering directory `/home/christian/node_modules/pg/build'
[1/2] cxx: src/binding.cc -> build/default/src/binding_1.o
../src/binding.cc:3:25: fatal error: node_events.h: No such file or directory
compilation terminated.
Waf: Leaving directory `/home/christian/node_modules/pg/build'
Build failed: -> task failed (err #1):
{task: cxx binding.cc -> binding_1.o}
I've been looking around for setting the node path, although haven't found anything of help so far - probably also because I'm totally new to nodejs, so I'd be happy about any hint.
我一直在寻找设置节点路径,尽管到目前为止还没有找到任何帮助 - 可能也是因为我对 nodejs 完全陌生,所以我很高兴任何提示。
回答by Chutirat Chaisan
Now, you have NodeJS installed in your Ubuntu. You should set /etc/environmentand load nodeJS path that can be executed by another users. For example:
现在,您已经在 Ubuntu 中安装了 NodeJS。您应该设置/etc/environment并加载可由其他用户执行的 nodeJS 路径。例如:
NODE="/home/ubuntu/local/node"
NODE_PATH="/usr/local/lib/node_modules"
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$NODE/bin:$NODE/lib/node_modules"
#PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
回答by Paul Rumkin
Do this in bash:
echo 'export NODE_PATH=~/local/:~/local/node_modules' >> ~/.bashrc
在 bash 中执行此操作:echo 'export NODE_PATH=~/local/:~/local/node_modules' >> ~/.bashrc
回答by eventsemitter
before things are fixed you must use node 0.5.1 (you can use gitk to revert the tree to this version)
在修复之前,您必须使用节点 0.5.1(您可以使用 gitk 将树恢复到此版本)
Auteur: Ryan Dahl <[email protected]> 2011-07-19 10:46:38
Auteur du commit: Ryan Dahl <[email protected]> 2011-07-19 10:46:38
Parent: 0a3fc1d9c8becc32c63ae736ca2b3719a3d03c5b (Remove StatWatcher's dep on C++ EventEmitter)
Enfant: 061ce7b0ac370c8a5ae93d95ab7da171cbd488f0 (net_uv: Fix simple/test-http-expect-continue.js)
Branche: master, remotes/origin/master
Suit: v0.5.1
Précède: v0.5.2
Finally remove node::EventEmitter
回答by David Shellabarger
I had the same problem. The issue was that I was specifying a old version of PG in my package.js After I removed the old version dependancy I was able to install PG without issue.
我有同样的问题。问题是我在 package.js 中指定了旧版本的 PG 删除旧版本依赖项后,我能够毫无问题地安装 PG。

