在Linux Mint下安装nodejs最简单的办法就是直接sudo apt-get install nodejs
当前的最新版本为Version: 0.6.12~dfsg1-1ubuntu1,个人觉得还是安装最新的稳定版本会比较好。
网上有人喜欢用git从GITHUB上直接获取nodejs的源代码,我觉得这样风险太大,因为这样获取的是最新的源代码。当然,我想应该可以在用git命令时设置参数来获取特定的版本。那样的话,还要熟悉git,难度加大了。所以我选择直接从nodejs的官网上下载最新的stable版本,当前为0.8.8,大致瞄了一眼它的release note:
2012.08.22, Version 0.8.8 (Stable)
-
V8: upgrade to 3.11.10.19
-
npm: upgrade to 1.1.59
-
windows: fix uninitialized memory access in uv_update_time() (Bert Belder)
-
unix, windows: fix memory corruption in fs-poll.c (Ben Noordhuis)
-
unix: fix integer overflow in uv_hrtime (Tim Holy)
-
sunos: fix uv_cpu_info() on x86_64 (Ben Noordhuis)
-
tls: update default cipher list (Ben Noordhuis)
-
unix: Fix llvm and older gcc duplicate symbol warnings (Bert Belder)
-
fs: fix use after free in stat watcher (Ben Noordhuis)
-
build: Fix using manually compiled gcc on OS X (Nathan Rajlich)
-
windows: make junctions work again (Bert Belder)
接下来,在bash中切换到下载目录,解压缩node-v0.8.8.tar.gz:
tar -xzvf node-v0.8.8.tar.gz
也可以右键点击压缩包选择extract here
然后进入解压出的目录并执行:
./configure
这一步会设定一些变量的值,并把这些值写入文件config.mk和config.gypi
1 # Do not edit. Generated by the configure script.
2 { 'target_defaults': { 'cflags': [],
3 'default_configuration': 'Release',
4 'defines': [],
5 'include_dirs': [],
6 'libraries': []},
7 'variables': { 'clang': 0,
8 'gcc_version': 46,
9 'host_arch': 'x64',
10 'node_install_npm': 'true',
11 'node_install_waf': 'true',
12 'node_prefix': '/opt',
13 'node_shared_openssl': 'false',
14 'node_shared_v8': 'false',
15 'node_shared_zlib': 'false',
16 'node_use_dtrace': 'false',
17 'node_use_etw': 'false',
18 'node_use_openssl': 'true',
19 'target_arch': 'x64',
20 'v8_no_strict_aliasing': 1,
21 'v8_use_snapshot': 'true'}}
其中有个变量叫node_prefix,它会设定nodejs的安装目录,默认值为/usr/local,例如在这边我设定为/opt。default_configuration说明安装哪种build模式:release或debug?
以上两种需求可以用如下配置方式实现:./configure --debug --prefix="/opt"
然后就是sudo make install,这个过程还是比较长的,我去了趟WC过来还没build完。;D
切换到/opt目录,发现多了几个文件夹,要提的是bin和share。bin里放的就是node的可执行文件,share里放的是node的man文件。
因为是默认情况下/opt/bin没有被加到PATH环境变量中,我们可以编辑~/.profile文件,在末尾加上:
| export PATH=$PATH:/opt/bin |
这个时候,我们输入man node,还是看不到node的帮助文档。打开/etc/manpath.config,在setup PATH to MANPATH mapping这一节追加
| MANPATH_MAP /opt/bin /opt/share/man |
然后是找到MANDB_MAP,然后追加
| MANDB_MAP /opt/share/man /var/cache/man/opt/share |
然后我们再次输入man node:
| NODE.JS(1) NODE.JS(1) NAME node - Server-side JavaScript SYNOPSIS node [ -v ] [ --debug | --debug-brk ] [ --v8-options ] [ -e command | script.js ] [ arguments ] Execute without arguments to start the REPL. DESCRIPTION Node is a set of libraries for javascript which allows it to be used outside of the browser. It is primarily focused on creating simple, easy to build network clients and servers. |
本文介绍在LinuxMint下手动安装Node.js的过程,包括下载、配置、编译和环境变量设置等步骤。
837

被折叠的 条评论
为什么被折叠?



