Ching-Chuan Chen's Blogger

Statistics, Machine Learning and Programming

0%

Using gcc 5.3 with R in CentOS 7

只是記錄一下,方便日後check

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# install devtoolset-4 to get gcc-5.3
yum install centos-release-scl
yum-config-manager --enable rhel-server-rhscl-7-rpms
yum install -y devtoolset-4 --exclude=devtoolset-4-4.1-3.el7,devtoolset-4-ide-4.1-3.el7
yum update -y

# enable usage of gcc-5.3
tee -a /etc/bashrc << EOF
source /opt/rh/devtoolset-4/enable
EOF
source /etc/bashrc

# install R from EPEL (default BLAS is openblas)
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y epel-release-latest-7.noarch.rpm
yum install -y R R-devel R-java libxml2-devel libxml2-static tcl tcl-devel tk tk-devel libtiff-static libtiff-devel libjpeg-turbo-devel libpng12-devel cairo-tools libicu-devel openssl-devel libcurl-devel freeglut readline-static readline-devel cyrus-sasl-devel

# install microsoft R open (default BLAS is MKL)
wget https://mran.microsoft.com/install/mro/3.3.2/microsoft-r-open-3.3.2.tar.gz
tar zxvf microsoft-r-open-3.3.2.tar.gz
yum install -y microsoft-r-open/rpm/microsoft-r-open-*

# install Oracle Java
curl -v -j -k -L -H "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-x64.rpm -o jdk-8u112-linux-x64.rpm
yum install -y jdk-8u112-linux-x64.rpm
tee -a /etc/bashrc << "EOF"
export JAVA_HOME=/usr/java/jdk1.8.0_112
export PATH=$PATH:$JAVA_HOME/bin
EOF
source /etc/bashrc

# remove R from EPEL, and use microsoft R open
rm -rf /usr/lib64/R
cp -r /usr/lib64/microsoft-r/3.3/lib64/R /usr/lib64
# let user access library dir (not to use personal library)
chmod -R 777 /usr/lib64/R/library

# config R java env
R CMD javareconf
# check Java and g++ work well
# (fail installation indicate configuration of java/g++ is wrong)
Rscript -e "install.packages(c('rJava', 'Rcpp'))"
Rscript -e "library(rJava); library(Rcpp)"

# make C++11 enable
sed -i -e 's/CXX1X =/CXX1X = g++/g' /usr/lib64/R/etc/Makeconf
sed -i -e 's/CXX1XFLAGS =/CXX1XFLAGS = -DU_STATIC_IMPLEMENTATIN -O2 -g/g' /usr/lib64/R/etc/Makeconf
sed -i -e 's/CXX1XPICFLAGS =/CXX1XPICFLAGS = -fpic/g' /usr/lib64/R/etc/Makeconf
sed -i -e 's/CXX1XSTD =/CXX1XSTD = -std=c++11/g' /usr/lib64/R/etc/Makeconf
# check g++ with CXX1X work well
# (fail installation indicate configuration of g++ with CXX1X is wrong)
Rscript -e "install.packages('RcppMLPACK')"

## install rstudio-server
wget https://download2.rstudio.org/rstudio-server-rhel-1.0.136-x86_64.rpm
yum install -y --nogpgcheck rstudio-server-rhel-1.0.136-x86_64.rpm

# let user not to use personal library
tee -a /etc/rstudio/rsession.conf << EOF
r-libs-user=/usr/lib64/R/library
EOF

# let rstudio-server uses gcc-5.3
tee -a /usr/lib/rstudio-server/R/ServerOptions.R << EOF
Sys.setenv(PATH = "/opt/rh/devtoolset-4/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin",
LD_LIBRARY_PATH = "/opt/rh/devtoolset-4/root/usr/lib64:/opt/rh/devtoolset-4/root/usr/lib:/usr/lib64/R/lib::/lib:/builddir/vendor/build/lib:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64/jre/lib/amd64/server")
EOF

# start rstudio-server
systemctl enable rstudio-server
systemctl start rstudio-server

# open firewall
firewall-cmd --zone=public --add-port=8787/tcp --permanent
firewall-cmd --reload

後來看到文章說,直接編譯安裝是比較快的方法:

1
2
3
4
5
6
7
yum install libmpc-devel mpfr-devel gmp-devel zlib-devel gcc gcc-c++ gcc-gfortran glibc-devel
wget ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-5.4.0/gcc-5.4.0.tar.gz
tar zxvf gcc-5.4.0.tar.gz
cd gcc-5.4.0
./configure --prefix=/usr --with-system-zlib --disable-multilib --enable-languages=c,c++,fortran
make -j 8
make install