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

Installing from source for all POSIX-like systems

Compiling Node.js from source follows this process:

  1. Download the source from http://nodejs.org/download.
  1. Configure the source for building using ./configure.
  2. Run make, then make install.

The source bundle can be downloaded with your browser, or as follows, substituting your preferred version:

$ mkdir src
$ cd src
$ wget https://nodejs.org/dist/v10.0.0/node-v10.0.0.tar.gz
$ tar xvfz node-v10.0.0.tar.gz
$ cd node-v10.0.0

Now we configure the source so that it can be built. This is just like many other open source packages, and there are a long list of options to customize the build:

$ ./configure --help

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

$ ./configure --prefix=$HOME/node/10.0.0
..output from configure  

If you're going to install multiple Node.js versions side by side, it's useful to put the version number in the path like this. That way, each version will sit in a separate directory. It's a simple matter of switching between Node.js versions by changing the PATH variable appropriately:

# On bash shell:
$ export PATH=${HOME}/node/VERSION-NUMBER/bin:${PATH}
# On csh
$ setenv PATH ${HOME}/node/VERSION-NUMBER/bin:${PATH}

A simpler way to install multiple Node.js versions is the nvm script described later.

If you want to install Node.js 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 will likely have successfully configured the source tree for installation in your chosen directory. If this doesn't succeed, the error messages that are printed will describe what needs to be fixed. Once the configure script is satisfied, you can go on to the next step.

With the configure script satisfied, you 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 that you add the installation directory to your PATH variable as follows:

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

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

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

This should result in some directories, as follows:

$ ls ~/node/10.0.0/
bin   include   lib   share
$ ls ~/node/10.0.0/bin  
主站蜘蛛池模板: 海伦市| 怀远县| 仁化县| 镶黄旗| 庄河市| 泉州市| 唐海县| 韩城市| 讷河市| 开封县| 沧源| 丹棱县| 巴彦县| 皋兰县| 邯郸县| 邵武市| 麟游县| 股票| 寿光市| 潍坊市| 璧山县| 比如县| 南和县| 石台县| 年辖:市辖区| 会同县| 丰原市| 白银市| 乡宁县| 东海县| 巴东县| 定安县| 长海县| 芒康县| 崇州市| 邳州市| 清原| 石屏县| 辰溪县| 贵定县| 海门市|