LoginSignup
8
6

More than 5 years have passed since last update.

CentOS6にNode.jsの導入[パッケージver]

Last updated at Posted at 2017-09-03

はじめに

開発環境を構築する程度であれば,nvmndenv を使って好きなバージョンを入れられるようにしておくと良いでしょう.

ちなみに私は,anyenvを使って 〇〇env 系を全て管理するのが一番良いのではないかと思います.
そちらの手順は割愛(参考

本題

CentOS6.x系は yum install nodejs npm とやっても古いバージョンのものしかインストールされません.

そのため,本家からパッケージをダウンロードする必要があります.

# Download
$ cd /usr/local/src
$ wget https://nodejs.org/dist/vX.Y.Z/node-vX.Y.Z.tar.gz
# Install
$ tar xzf node-vX.Y.Z.tar.gz
$ cd node-vX.Y.Z
$ ./configure
$ make install

しかし,./configureあたりで以下のような警告が発せられます.

WARNING: C++ compiler too old, need g++ 4.8 or clang++ 3.4 (CXX=g++)

これはCentOS6のgccのバージョンが古いために発生します.
この状態で make installを行うとビルドエラーが置きます.

解決策

そこで,まずは gccのバージョンをアップデートしましょう.
今回は必要最低限の構成にするため,devtoolset-2を用いてgccのバージョンを4.8までアップデートします.

その後改めてnode.jsをインストールしましょう.

手順

devtoolset-2のインストール

# Register Repo
$ cd /etc/yum.repos.d/
$ wget http://people.centos.org/tru/devtools-2/devtools-2.repo 
# Install devtoolset-2
$ yum install -y devtoolset-2-gcc devtoolset-2-gcc-c++ devtoolset-2-binutils
# enable devtoolset-2
$ scl enable devtoolset-2 bash

node.js のインストール

$ cd /usr/local/src/node-vX.Y.Z
$ ./configure
$ make install

ここでmake installが完了すればインストール完了です.

# Node version
$ node -v
# npm version
$ npm -v

wgetが使えなかったら,wgetで指定したURLにアクセスして,ソースコードをダウンロードして同じ場所に配置しましょう.

以上!

8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6