1.包管理安裝
百度一堆亂七八糟的教程,加上node各種版本,其實官方穩定就有包管理的安裝方法,幾條命令就可以安裝好各種版本。
官方文檔地址:https://nodejs.org/en/download/package-manager/
Run as root on RHEL, CentOS or Fedora, for Node.js v4 LTS Argon:
curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
Alternatively for Node.js v6:
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
Alternatively for Node.js 0.10:
curl --silent --location https://rpm.nodesource.com/setup | bash -
Then install, as root:
yum -y install nodejs
就這樣,不能再簡單。
2.源碼安裝
來自官方文檔(會看官方文檔多重要)
https://github.com/nodejs/node/wiki/Installation
准備命令:
yum -y install gcc make gcc-c++ openssl-devel wget
下面是安裝版本0.12.7,安裝其他版本只需要替換掉就行,所有版本地址:https://nodejs.org/dist/
ver=0.12.7 #Replace this with the latest version available
wget -c https://nodejs.org/dist/v$ver/node-v$ver.tar.gz #This is to download the source code.
tar -xzf node-v$ver.tar.gz
cd node-v$ver
./configure && make && sudo make install
驗證是否安裝配置成功:
node -v