LoginSignup
11
10

More than 5 years have passed since last update.

centos6.xでnodejs4.xを利用する

Last updated at Posted at 2015-09-29

1.問題点

先に問題点を上げておく

  • centosの標準のg++のバージョンが古いのでコンパイルできない(gcc4.8以降必須)
  • gcc4.8でコンパイルして作ったrpmをgcc4.8を入れていないマシンで動かすことはできる
  • gcc4.8がインストールされていない環境ではnpmでモジュールをビルドできないので動かない可能性がある
  • もうgccが古いのでcentos7に移行する選択肢も考えよう

2.リポジトリからyumでインストールする場合

nodesourceのリポジトリからインストールする

curl -sL https://rpm.nodesource.com/setup_4.x | bash -
yum install -y nodejs gcc-c++ make

後述するnpmで問題がでるのでgccの新しいバージョンをインストールする

yum install -y wget
wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo
yum install -y devtoolset-2-gcc devtoolset-2-gcc-c++ devtoolset-2-binutils

3.自分でrpmをビルドする場合

ビルド環境をインストールする

gcc4.8(devtoolsets-2)をインストール

curl http://people.centos.org/tru/devtools-2/devtools-2.repo > /etc/yum.repos.d/devtools-2.repo
yum install -y devtoolset-2-gcc devtoolset-2-gcc-c++ devtoolset-2-binutils

ビルドに必要なツールをインストールする

yum install -y centos-release-SCL
yum install -y python27
yum install -y yum-utils rpmdevtools make git

rpmを作成する

kazuhisyaさんがgithubで公開しているrpm作成ツールを使うのが簡単。

git clone -b LTS https://github.com/kazuhisya/nodejs-rpm.git
cd nodejs-rpm
yum-builddep ./nodejs.spec
scl enable python27 devtoolset-2 'make rpm'

※ビルドに時間が相当かかります

rpmのインストール

cd ./dist/RPMS/x86_64/
yum install -y nodejs-4.1.2-1.el6.x86_64.rpm nodejs-npm-4.1.2-1.el6.x86_64.rpm

4.npmを使う場合の注意点

以下のようにインストール指定する

scl enable devtoolset-2 "npm install bufferutil"

指定しない場合のエラー

../src/bufferutil.cc:114: error: variable or field ‘init’ declared void
../src/bufferutil.cc:114: error: ‘Handle’ was not declared in this scope
../src/bufferutil.cc:114: error: expected primary-expression before ‘>’ token
../src/bufferutil.cc:114: error: ‘target’ was not declared in this scope
../src/bufferutil.cc:120: error: ‘init’ was not declared in this scope
../src/bufferutil.cc:120: error: too many initializers for ‘node::node_module’
In file included from ../src/bufferutil.cc:16:
../node_modules/nan/nan.h: In function ‘void Nan::SetMethod(const T&, const char*, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&)) [with T = v8::Local<v8::FunctionTemplate>]’:
../src/bufferutil.cc:30:   instantiated from here
../node_modules/nan/nan.h:1829: error: ‘GetFunction’ was not declared in this scope
make: *** [Release/obj.target/bufferutil/src/bufferutil.o] エラー 1
make: ディレクトリ `/root/node_modules/bufferutil/build' から出ます
11
10
1

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
11
10