Centos 安装 Node.js

7,982 阅读1分钟

Yum安装

只能安装第三方仓库中存在的版本,一般落后 node 最新版本

  1. 安装EPEL 仓库
    yum install epel-release
  2. 安装 nodejs
    yum install nodejs
  3. 安装 npm yum install npm

源码安装

源码安装需要 最好将源码解压到 usr/local/xxx 目录下面再执行 安装
再添加 到环境变量

  1. 官网下载 最新的源码包
    wget http://nodejs.org/dist/v0.12.0/node-v0.12.0.tar.gz

  2. 解压下载的tar
    tar xvf node-v0.12.0.tar.gz

  3. 进入解压之后的目录
    cd node-v*

  4. 编译之前 安装编译扩展
    yum install gcc gcc-c++

  5. 开始编译

   ./configure  --prefix=/usr/local/node  
    make  
    make install

官网推荐安装方式

https://nodejs.org/en/download/package-manager/ Enterprise Linux and Fedora

Including Red Hat® Enterprise Linux® / RHEL, CentOS and Fedora.

Node.js is available from the NodeSource Enterprise Linux and Fedora binary distributions repository. Support for this repository, along with its scripts, can be found on GitHub at nodesource/distributions.

Note that the Node.js packages for EL 5 (RHEL5 and CentOS 5) depend on the EPEL repository being available. The setup script will check and provide instructions if it is not installed.

On RHEL, CentOS or Fedora, for Node.js v8 LTS:

curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -

Then install:

yum -y install nodejs

Optional: install build tools

To compile and install native addons from npm you may also need to install build tools:

sudo yum install gcc-c++ make
# or: sudo yum groupinstall 'Development Tools'