Ubuntu 12.04 LTS 64bit
一、 通过apt-get安装nodejs – 失败(可以下面的看源码安装方法):
复制代码 代码如下:
~ sudo apt-get install nodejs
~ sudo apt-get install npm
~ node -v
v0.6.12
~ npm -v
1.1.4
创建工作目录
复制代码 代码如下:
~ mkdir workspace
~ mkdir workspace/nodejs
~ cd workspace/nodejs
~ pwd
/home/conan/workspace/nodejs
安装失败
复制代码 代码如下:
sudo npm install express -g
npm http GET https://registry.npmjs.org/express
npm http 304 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/connect/2.7.11
npm http GET https://registry.npmjs.org/commander/0.6.1
npm http GET https://registry.npmjs.org/range-parser/0.0.4
npm http GET https://registry.npmjs.org/mkdirp/0.3.4
npm http GET https://registry.npmjs.org/cookie/0.1.0
npm http GET https://registry.npmjs.org/buffer-crc32/0.2.1
npm http GET https://registry.npmjs.org/fresh/0.1.0
npm http GET https://registry.npmjs.org/methods/0.0.1
npm http GET https://registry.npmjs.org/send/0.1.0
npm http GET https://registry.npmjs.org/cookie-signature/1.0.1
npm http GET https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/commander/0.6.1
npm http 304 https://registry.npmjs.org/connect/2.7.11
npm http 304 https://registry.npmjs.org/range-parser/0.0.4
npm http 304 https://registry.npmjs.org/mkdirp/0.3.4
npm http 304 https://registry.npmjs.org/cookie/0.1.0
npm http 304 https://registry.npmjs.org/buffer-crc32/0.2.1
npm http 304 https://registry.npmjs.org/fresh/0.1.0
npm http 304 https://registry.npmjs.org/methods/0.0.1
npm http 304 https://registry.npmjs.org/send/0.1.0
npm http 304 https://registry.npmjs.org/cookie-signature/1.0.1
npm http 304 https://registry.npmjs.org/debug
npm ERR! error installing express@3.2.6
npm ERR! error rolling back express@3.2.6 Error: UNKNOWN, unknown error '/usr/local/lib/node_modules/express'
npm ERR! Unsupported
npm ERR! Not compatible with your version of node/npm: connect@2.7.11
npm ERR! Required: {"node":">= 0.8.0"}
npm ERR! Actual: {"npm":"1.1.4","node":"0.6.12"}
npm ERR!
npm ERR! System Linux 3.5.0-23-generic
npm ERR! command "node" "/usr/bin/npm" "install" "express" "-g"
npm ERR! cwd /home/conan/workspace/nodejs
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.1.4
npm ERR! code ENOTSUP
npm ERR! message Unsupported
npm ERR! errno {}
npm http GET https://registry.npmjs.org/mime/1.2.6
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/conan/workspace/nodejs/npm-debug.log
npm not ok
系统提示, node和npm版本不兼容。可能是终于apt-get源没有更新造成的问题。
二、从github下载源代码安装 – 成功
下面要找到兼容的版本,手动安装。
先卸载刚刚装的node和npm
复制代码 代码如下:
~ sudo apt-get autoremove npm
~ sudo apt-get autoremove nodejs
找到nodejs的官方发布下载:https://github.com/joyent/node
在ubuntu中,先安装git
复制代码 代码如下:
~ sudo apt-get install git
然后,从github下载nodejs源代码
复制代码 代码如下:
~ git clone git://github.com/joyent/node.git
Cloning into 'node'...
remote: Counting objects: 100200, done.
remote: Compressing objects: 100% (28074/28074), done.
remote: Total 100200 (delta 78807), reused 90936 (delta 70473)
Receiving objects: 100% (100200/100200), 61.81 MiB | 698 KiB/s, done.
Resolving deltas: 100% (78807/78807), done.
进入node目录
复制代码 代码如下:
~ cd node
~ pwd
/home/conan/workspace/nodejs/node
切换最新的release的版本v0.11.2-release
复制代码 代码如下:
~ git checkout v0.11.2-release
Branch v0.11.2-release set up to track remote branch v0.11.2-release from origin.
Switched to a new branch 'v0.11.2-release'
进行安装
复制代码 代码如下:
./configure
make
sudo make install
安装完成,查看node版本
复制代码 代码如下:
~ node -v
-bash: /usr/bin/node: No such file or directory
提示错误,没有找到node,查一下node安装位置
复制代码 代码如下:
~ whereis node
node: /usr/local/bin/node
增加软链接:node和npm到/usr/bin
复制代码 代码如下:
~ sudo ln -s /usr/local/bin/node /usr/bin/node
~ sudo ln -s /usr/local/bin/npm /usr/bin/npm
我们再查看node和npm版本
复制代码 代码如下:
~ node -v
v0.11.2
~ npm -v
1.2.21
下面安装express
复制代码 代码如下: