현재 CentOS 6.9 버전의 gcc 버전은 4.4.7이다.

 

[root@CentOS6 ~]# gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

그런데 Node.js 최신 버전을 컴파일 설치하려면 gcc 4.8.5 이상이 필요하다. CentOS 7에는 gcc 버전이 4.8.5이나 Node.js 하나 컴파일 하고자 OS를 변경할 이유는 없다. 물론 gcc 소스를 직접 다운로드 받아 컴파일 설치하는 방법도 있다. 하지만 gcc 뿐 아니라 다른 라이브러리 버전 등 걸리는 문제들이 많기 때문에 험난한 길이고, 특히 gcc는 컴파일 설치하는데만 수십분이 소요되는 작업이다.

 

이러한 고민을 한방에 해결해줄 수 있는 툴이 바로 Devtoolset 계열이다.

 

https://www.softwarecollections.org/en/scls/rhscl/devtoolset-3/

 

devtoolset-3 - Developer Toolset is designed for developers working on CentOS or Red Hat Enterprise Linux platform. It provides current versions of the GNU Compiler Collection, GNU Debugger, Eclipse development platform, and other development, debugging, and performance monitoring tools.

 

설치는 매우 간단하다. 두 줄이면 된다. toolchain을 설치하면 컴파일러, 디버거 등이 설치된다.

 

yum -y install centos-release-scl
yum -y install devtoolset-3-toolchain

 

이렇게 설치하면 아래와 같이 /opt/rh/devtoolset-3/root 아래 필요한 파일들이 설치된다.

 

[root@CentOS6 ~]# ll /opt/rh/devtoolset-3/root
total 76
dr-xr-xr-x.  2 root root 4096 Oct  3  2015 bin
dr-xr-xr-x.  2 root root 4096 Oct  3  2015 boot
drwxr-xr-x.  2 root root 4096 Oct  3  2015 dev
drwxr-xr-x. 14 root root 4096 May 21 11:05 etc
drwxr-xr-x.  2 root root 4096 Oct  3  2015 home
dr-xr-xr-x.  3 root root 4096 May 21 11:05 lib
dr-xr-xr-x.  3 root root 4096 May 21 11:05 lib64
drwxr-xr-x.  2 root root 4096 Oct  3  2015 media
drwxr-xr-x.  2 root root 4096 Oct  3  2015 mnt
drwxr-xr-x.  2 root root 4096 Oct  3  2015 opt
dr-xr-xr-x.  2 root root 4096 Oct  3  2015 proc
dr-xr-x---.  2 root root 4096 Oct  3  2015 root
dr-xr-xr-x.  2 root root 4096 Oct  3  2015 sbin
drwxr-xr-x.  2 root root 4096 Oct  3  2015 selinux
drwxr-xr-x.  2 root root 4096 Oct  3  2015 srv
drwxr-xr-x.  2 root root 4096 Oct  3  2015 sys
drwxrwxrwt.  2 root root 4096 Oct  3  2015 tmp
drwxr-xr-x. 13 root root 4096 May 21 11:05 usr
drwxr-xr-x. 17 root root 4096 May 21 11:05 var

 

위 환경을 환경변수에 적용하여 새로운 shell을 띄우려면 아래와 같이 입력하면 된다.

 

scl enable devtoolset-3 bash

 

또는 source나 . 으로 직접 현재 shell에 반영해도 동일할 듯

 

source /opt/rh/devtoolset-3/enable

 

이 상태로 gcc 버전을 확인해보면 4.9.2가 나온다.

 

[root@CentOS6 ~]# which gcc
/opt/rh/devtoolset-3/root/usr/bin/gcc
[root@CentOS6 ~]# gcc --version
gcc (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

위와같은 환경에서는 비록 CentOS 6 버전이지만 Node.js를 컴파일 설치할 수 있다.

 

CentOS 6 환경에서 gcc 버전 때문에 고민이라면 devtoolset 활용을 고려해보시길...