- Node Web Development(Second Edition)
- David Herron
- 629字
- 2021-08-13 16:46:53
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:
- Node version manager: https://github.com/visionmedia/n
- Nodefront, aids in rapid frontend development: http://karthikv.github.io/nodefront/
- Microsoft Exchange Server PowerShell Cookbook(Third Edition)
- 深入淺出Electron:原理、工程與實踐
- Mastering LibGDX Game Development
- Python高效開發實戰:Django、Tornado、Flask、Twisted(第3版)
- 軟件測試技術指南
- 持續集成與持續交付實戰:用Jenkins、Travis CI和CircleCI構建和發布大規模高質量軟件
- Python函數式編程(第2版)
- Learning Jakarta Struts 1.2: a concise and practical tutorial
- 現代CPU性能分析與優化
- Software Development on the SAP HANA Platform
- Test-Driven iOS Development with Swift
- Microsoft Windows Identity Foundation Cookbook
- JavaWeb入門經典
- WCF 4.5 Multi-Layer Services Development with Entity Framework(Third Edition)
- 軟件定義存儲:原理、實踐與生態