从http://nodejs.org下载最新的node.js源码压缩包
假设解压后的目录为~/node
cd ~/node
# 打算把nodejs安装在/opt目录下
./configure --prefix=/opt/nodejs
make
make install
安装完毕后,将/opt/nodejs/bin添加到PATH环境变量
常见错误:
1) 找不到openssl
Checking for openssl : not found
Checking for function SSL_library_init : not found
Checking for header openssl/crypto.h : not found
/data/node-v0.4.9/wscript:341: error: Could not autodetect OpenSSL support. Make
sure OpenSSL development packages are installed. Use configure --without-ssl to
disable this message.
安装openssl-devel模块即可,ubuntu安装的是libssl-dev。
sudo apt-get install libssl-dev
sudo apt-get install pkg-config
2)找不到g++和gcc
sudo apt-get install g++
sudo apt-get install gcc
sudo ln -s /usr/local/bin/node /usr/bin/node
sudo ln -s /usr/local/lib/node /usr/lib/node
sudo ln -s /usr/local/bin/npm /usr/bin/npm
sudo ln -s /usr/local/bin/node-waf /usr/bin/node-waf
4)libssl.so.0.9.8没有安装
support/node-builds-v4/node-linux32: error while loading shared libraries: libssl.so.0.9.8: cannot open shared object file: No such file or directory
sudo apt-get install libssl0.9.8
参考资料
http://comments.gmane.org/gmane.comp.lang.javascript.nodejs/5780
http://www.hacksparrow.com/nodejs-error-could-not-autodetect-openssl-support.html