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

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:

主站蜘蛛池模板: 苗栗县| 台南市| 昌平区| 克什克腾旗| 兴安县| 丹寨县| 墨脱县| 庆城县| 涪陵区| 浮梁县| 洮南市| 敦煌市| 勃利县| 礼泉县| 项城市| 晋城| 南开区| 黔西县| 辽宁省| 祁连县| 紫金县| 本溪市| 玉林市| 屯留县| 平度市| 文水县| 东安县| 云梦县| 五指山市| 安新县| 桐庐县| 浮梁县| 吉林市| 原阳县| 兴业县| 郧西县| 乐平市| 张家口市| 抚远县| 武强县| 云南省|