官术网_书友最值得收藏!

Installing developer tools on Mac OS X

The developer tools (such as GCC) are an optional installation on Mac OS X. There are two ways to get those tools, both of which are free. On the OS X installation DVD is a directory labeled Optional Installs, in which there is a package installer for—among other things—the developer tools, including Xcode.

The other method is to download the latest copy of Xcode (for free) from http://developer.apple.com/xcode/.

Most other POSIX-like systems, such as Linux, include a C compiler with the base system.

Installing from source for all POSIX-like systems

First, download the source from http://nodejs.org/download. One way to do this is with your browser, and another way is as follows:

$ mkdir src
$ cd src
$ wget http://nodejs.org/dist/v0.10.7/node-v0.10.7.tar.gz
$ tar xvfz node-v0.10.7.tar.gz
$ cd node-v0.10.7

The next step is to configure the source so that it can be built. It is done with the typical sort of configure script and you can see its long list of options by running the following:

 $ ./configure –help.

To cause the installation to land in your home directory, run it this way:

$ ./configure –prefix=$HOME/node/0.10.7
..output from configure

If you want to install Node in a system-wide directory simply leave off the -prefix option, and it will default to installing in /usr/local.

After a moment it'll stop and more likely configure the source tree for installation in your chosen directory. If this doesn't succeed it will print a message about something that needs to be fixed. Once the configure script is satisfied, you can go on to the next step.

With the configure script satisfied, compile the software:

$ make
.. a long log of compiler output is printed
$ make install

If you are installing into a system-wide directory do the last step this way instead:

 $ make
 $ sudo make install

Once installed you should make sure to add the installation directory to your PATH variable as follows:

$ echo 'export PATH=$HOME/node/0.10.7/bin:${PATH}' >>~/.bashrc
$ . ~/.bashrc

For csh users, use this syntax to make an exported environment variable:

$ echo 'setenv PATH $HOME/node/0.10.7/bin:${PATH}' >>~/.cshrc
$ source ~/.cshrc

This should result in some directories like this:

$ ls ~/node/0.10.7/
bin include lib share
$ ls ~/node/0.10.7/bin
node node-waf npm

Maintaining multiple Node installs simultaneously

Normally you won't have multiple versions of Node installed, and doing so adds complexity to your system. But if you are hacking on Node itself, or are testing against different Node releases, or any of several similar situations, you may want to have multiple Node installations. The method to do so is a simple variation on what we've already discussed.

If you noticed during the instructions discussed earlier, the –prefix option was used in a way that directly supports installing several Node versions side-by-side in the same directory:

$ ./configure –prefix=$HOME/node/0.10.7

And:

$ ./configure –prefix=/usr/local/node/0.10.7

This initial step determines the install directory. Clearly when Version 0.10.7, Version 0.12.15, or whichever version is released, you can change the install prefix to have the new version installed side-by-side with the previous versions.

To switch between Node versions is simply a matter of changing the PATH variable (on POSIX systems), as follows:

$ export PATH=/usr/local/node/0.10.7/bin:${PATH}

It starts to be a little tedious to maintain this after a while. For each release, you have to set up Node, npm, and any third-party modules you desire in your Node install; also the command shown to change your PATH is not quite optimal. Inventive programmers have created several version managers to make this easier by automatically setting up not only Node, but npm also, and providing commands to change your PATH the smart way:

主站蜘蛛池模板: 涿鹿县| 巨鹿县| 灵丘县| 漯河市| 海兴县| 都江堰市| 乐平市| 酒泉市| 嵊泗县| 苍溪县| 安西县| 丘北县| 隆尧县| 太仓市| 宁陵县| 改则县| 长子县| 都安| 海阳市| 忻城县| 益阳市| 铜陵市| 商都县| 衡水市| 曲松县| 泰宁县| 九江县| 克拉玛依市| 五寨县| 澜沧| 石渠县| 瑞金市| 彰化县| 司法| 遂宁市| 河间市| 芒康县| 凌海市| 武胜县| 巴林右旗| 宜宾县|