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

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:

主站蜘蛛池模板: 鹤壁市| 高陵县| 邵武市| 迁安市| 舟山市| 光泽县| 平谷区| 江油市| 大新县| 江山市| 鄂尔多斯市| 无锡市| 扬中市| 抚顺县| 浪卡子县| 咸阳市| 酉阳| 泸溪县| 五大连池市| 南漳县| 西藏| 余干县| 文昌市| 深州市| 永州市| 东乡县| 蒲城县| SHOW| 民权县| 本溪| 建昌县| 临清市| 贵定县| 饶阳县| 天长市| 勃利县| 双牌县| 鄂托克旗| 修武县| 武宣县| 临湘市|