文档章节

Building and installing Node.js

b
 bill_wu
发布于 2014/05/16 05:08
字数 1236
阅读 68
收藏 0

Building and installing Node.js

You may build the Node.js engine for any of the supported platforms.

For Windows and Mac some pre-built binaries are available; you may install them without building Node for yourself.

Prerequisites and known issues of building

Prerequisites

  • GCC 4.2 or newer

  • GNU make 3.81 or newer. Pre-installed on most systems. Sometimes called gmake.

  • python 2.6 or 2.7. The build tools distributed with Node run on python.

  • libssl-dev (Node v0.6.x only.) Can usually be installed on *NIX systems with your favorite package manager. Pre-installed on OS X.

  • libexecinfo (FreeBSD and OpenBSD only.) Required by V8. pkg_add -r libexecinfoinstalls it.

Known Issues

On UNIX platforms, make sure that the path doesn't contain whitespace: /home/user/My Projects/node won't work.

If you receive an error during ./configure like this

File "/home/flo/node-v0.6.6/tools/waf-light", line 157, in <module>
     import Scripting
File "/home/flo/node-v0.6.6/tools/wafadmin/Scripting.py", line 146
     except Utils.WafError, e:
                          ^
SyntaxError: invalid syntax

it is because Python3 is your default Python version. To fix this issue you have to set Python2 temporary as your default Python:

export PYTHON=`which python2`

Maybe you need to change your PYTHONHOME as well. If that doesn't work, you can try creating symlinks to the old python in a directory which comes before python's in $PATH:

cd /usr/local/bin
ln -s /usr/bin/python2 python
ln -s /usr/bin/python2-config python-config

Remember to remove the symlinks when you're done. If you have any further installation problems stop into #node.js on irc.freenode.net and ask questions.

If you are compiling on a NFS mount and get errors at the linker stage, try this:

make LINK=g++

Building on GNU/Linux and other UNIX

There's a number of ways to install Node.js on Linux, instructions for installing Node.js on specific Linux distributions using a package manager can be found at: Installing Node.js via package manager.

The filenames vary with the Node's version. The following examples are for Node v0.6.18.

Do something like this

tar -zxf node-v0.6.18.tar.gz #Download this from nodejs.orgcd node-v0.6.18
./configure && make && sudo make install

If you are installing on an illumos 64 bit system consider the following to enable dtrace support

tar -zxf node-v0.6.18.tar.gz #Download this from nodejs.orgcd node-v0.6.18
./configure --with-dtrace --dest-cpu=x64 && make && sudo make install

Or, if you'd like to install from the repository

git clone https://github.com/joyent/node.gitcd node
git checkout v0.6.18 #Try checking nodejs.org for what the stable version is./configure && make && sudo make install

You may wish to install Node in a custom folder instead of a global directory.

./configure --prefix=/opt/node && make && sudo make install

You can really speed up building process by adding -j argument with a number usually approximately equals number of cores plus one, so make -j 3 would be appropriate for dual-core processor.

You may want to put the node executables in your path as well for easier use. Add this line to your~/.profile or ~/.bash_profile or ~/.bashrc or ~/.zshenv

export PATH=$PATH:/opt/node/bin

If you have SpiderMonkey installed, you may have some conflicting includes. Set CXXFLAGS="-I./deps/v8/src" before building to prioritize the v8 files over SpiderMonkey's.

Or use the one liner to install the latest node.js : bash < <(curl http://h3manth.com/njs)

Mac OSX

It's easiest to use a package manager (as mentioned above) such as brew or macports.

Building on Mac OSX 10.8 with Xcode 4.5

  1. Install Command Line Tools
    Xcode: Preferences->Downloads install Command Line Tools
    Note: I installed Xcode 4.5 in /Applications/Xcode

  2. Download node.js src code

git clone https://github.com/joyent/node.git
cd node
git checkout v0.8.2
  1. Compiling Source Code

export CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
export CXX=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
./configure && make && sudo make install

Building on Windows

vcbuild.bat nosign release x64 : Build in release mode in 64-bits

vcbuild.bat nosign debug x64 : Build in debug mode for 64-bits

vcbuild.bat nosign release : Build in release mode in 32-bits

vcbuild.bat clean : Clean Project

You need to have Microsoft Visual Studio 2012 or 2010 (Express edition is fine) as well as Python 2.6 or 2.7. Openssl is not required. Make sure that python is in your PATH.

The underneath is a example of building node in 64-bits debug mode.

c:\_GIT\node>.\vcbuild.bat debug x64
ctrpp not found in WinSDK path--using pre-gen files from tools/msvs/genfiles.
{ 'target_defaults': { 'cflags': [],
                       'default_configuration': 'Debug',
                       'defines': ['OPENSSL_NO_SSL2=1'],
                       'include_dirs': [],
                       'libraries': []},
  'variables': { 'clang': 0,
                 'host_arch': 'x64',
                 'node_install_npm': 'true',
                 'node_prefix': '',
                 'node_shared_cares': 'false',
                 'node_shared_http_parser': 'false',
                 'node_shared_libuv': 'false',
                 'node_shared_openssl': 'false',
                 'node_shared_v8': 'false',
                 'node_shared_zlib': 'false',
                 'node_tag': '',
                 'node_use_dtrace': 'false',
                 'node_use_etw': 'true',
                 'node_use_mdb': 'false',
                 'node_use_openssl': 'true',
                 'node_use_perfctr': 'true',
                 'node_use_systemtap': 'false',
                 'python': '**c:\\Python27\\python.exe**',
                 'target_arch': 'x64',
                 'v8_enable_gdbjit': 0,
                 'v8_no_strict_aliasing': 1,
                 'v8_use_snapshot': 'true',
                 'visibility': ''}}
creating  config.gypi
creating  config.mk
Project files generated.
  ares_platform.c
  inet.c
  js2c, and also js2c_experimental
  Assembling c:\_GIT\node\deps\openssl\openssl\crypto\bn\asm\x86_64-win32-masm.asm to Debug\obj\openssl\x86_64-win32-masm.obj.
  http_parser.c
  node_js2c
  ...
[Wait a few minutes]
C:\_GIT\node\Build\Debug\node.exe
> process.versions
{ http_parser: '1.0',
  node: '0.11.7-pre',
  v8: '3.20.14.1',
  uv: '0.11.9',
  zlib: '1.2.3',
  modules: '0x000C',
  openssl: '1.0.1e' }
>

The executable will be in Build\Debug\node.exe.

Managing multiple version of Visual Studio

Lets assume that you have two versions of Visual Studio installed. In this case, you may build against a specific Visual Studio Version. If you want to force a specific version of Visual Studio, you may use the variable GYP_MSVS_VERSION.

Example : Force Visual Studio 2012 set GYP_MSVS_VERSION=2012

Installing without building

You may obtain pre-compiled Node.js binaries for several platforms fromhttp://nodejs.org/download.

Installing on Windows

Manual install

Installing Node manually is recommended as a workaround for any problems with automatic install. You also have much better understanding of the things that happen if you do those things yourself.

The http://nodejs.org/dist/latest/ directory contains executables of the last version of Node.js engine (the engine only, i.e. without npm):

The http://nodejs.org/dist/npm/ directory contains the latest .zip archive of npm (such as npm-1.1.16.zip when npm v1.1.16 was the latest).

Manual installation steps:

  1. Make a clean directory and add that directory to your system's PATH variable.

  2. Download the latest node.exe to that directory.

  3. Download the latest npm's .zip file and unpack its contents to the same directory.

Then, with the usual help of PATH, you'll be able to run scripts (node scriptname.js) and install modules (npm install modulename) in any directory.

Manual update

To update Node, download the latest http://nodejs.org/dist/latest/node.exe (orhttp://nodejs.org/dist/latest/x64/node.exe for 64bit systems) and replace your old node.exe with it.

To update npm, run the npm update npm -g command.

Automatic install (with Microsoft Installer)

The http://nodejs.org/dist/latest/ directory contains the latest .msi package (such as node-v0.6.15.msi when Node v0.6.15 was the latest) that you may use to install both Node.js engine and npm.

Installing on Mac

The http://nodejs.org/dist/latest/ directory contains the latest .pkg package (such as node-v0.6.15.pkg when Node v0.6.15 was the latest).

Installing on Linaro Ubuntu (ARM, UDOO)

Compiled binaries and build instructions are available here.

Upgrading on Mac with .pkg

You can download the latest .pkg and run the installer and it will overwrite the existing version of Node currently installed.


本文转载自:https://github.com/joyent/node/wiki/Installation

b
粉丝 1
博文 27
码字总数 3992
作品 0
广州
私信 提问
ubuntu下安装最新版的nodejs方法

在nodejs官网 看到目前最新版本已经是0.12.5,虽然上面0.10版本也能工作,但是总是不爽。 在官网找到这个文章 Installing Node.js via package manager 发现里面安装的方法和上面类似,但是c...

tbaby
2015/05/07
0
1
Ubuntu 14.04 Ruby,ROR环境搭建

在看国外一个物联网平台thingsquare,因为它是用Ruby写的,所以就装个Ruby研究下。下面是搭建步骤。 步骤0 - 安装系统需要的包 # For Mac # 先安装 Xcode 开发工具,它将帮你安装好 Unix 环境...

quanpower
2014/08/02
0
0
npm v2.15.6 发布,Node.js 包管理工具

npm v2.15.6 发布了,npm是 Node.js 的包管理工具,用来安装各种 Node.js 的扩展。 以下是该版本值得关注的内容: #5135 Fix a bug where peerDependencies & shrinkwraps didn't play nice ...

oschina
2016/05/16
1K
10
Docer 和虚拟机的一些对比 [翻译]

本文翻译自:《Docker: Git for deployment -- Scout》,个人感觉它的内容和标题不对,所以就没有直译过来,要是我理解错了请帮忙纠正。 我听说了 多么令人惊叹,但是它并没有征服我的心,直...

BearCatYN
2015/03/30
0
0
在 Mac OS X 上玩 Node.js (30分钟教程)

今天我决定在 Mac OS X Lion 上玩玩 node.js 如果你还不清楚 Node.js 是什么,请点击这里查看详细介绍。 这里有一篇很好的 Node.js 介绍文章 great nodejs intro ,它将给你一个非常方便的介...

王振威
2012/11/26
4.8K
0

没有更多内容

加载失败,请刷新页面

加载更多

RocketMQ的事务投递

RocketMQ的事务投递 这是阿里的分布式事务图: 1、A服务先发送个Half Message给Brock端,消息中携带 B服务 即将要+100元的信息。 2、当A服务知道Half Message发送成功后,那么开始第3步执行本...

春哥大魔王的博客
20分钟前
1
0
Qt编写自定义控件31-面板仪表盘控件

一、前言 在Qt自定义控件中,仪表盘控件是数量最多的,写仪表盘都写到快要吐血,可能是因为各种工业控制领域用的比较多吧,而且仪表盘又是比较生动直观的,这次看到百度的echart中有这个控件...

飞扬青云
25分钟前
1
0
DisplayPort 迎来重大更新,数据带宽性能提高3倍

VESA宣布了他们对DisplayPort接口三年来的第一次重大更新。 与DP 1.4a相比,DisplayPort 2.0提供了三倍于DP 1.4a的数据带宽性能,支持超过8K的分辨率,更高的刷新率和更高分辨率的HDR,以及其...

linuxCool
32分钟前
1
0
《Linux就该这么学》2019年7月20日第八天上课笔记

du命令 du -sh /newFS/ 察看文件/文件夹数据占用量 SWAP 交换分区的设置 磁盘容量配额 RHEL 5/6 usrquota RHEL 7 quota 软硬连接 ln 软 指针指向inode 硬 建立新的inode RAID 0 1 5 1+0...

2lodoss
35分钟前
1
0
适合钱包应用开发的ERC20代币数据集

Erc20Tokens数据集包含超过1000种主流的以太坊ERC20代币的描述数据清单和图标,可用于钱包等区块链应用的开发,支持使用Java、Python、Php、NodeJs、C#等各种开发语言查询主流ERC20代币的相关...

汇智网教程
59分钟前
1
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部