CentOS6 编译安装R-3.6.1 (更新R-4.0.3安装方法)

1. 安装依赖(有root权限)

#绘图相关
yum install libjpeg-devel
yum install libtiff-devel
yum install cairo-devel
yum install libpng-devel
yum install libicu-devel

# X11
yum install libXt-devel
yum install libX11-devel

yum install readline-devel
yum install zlib-devel
yum install bzip2-devel
yum install xz-devel
yum install pcre-devel
yum install openssl-devel
yum install curl-devel

2. 安装依赖(无root权限)

1) 下载安装ncurses

wget http://ftp.gnu.org/gnu/ncurses/ncurses-6.1.tar.gz
tar zxvf ncurses-6.1.tar.gz
cd ncurses-6.1
./configure --prefix=/home/test/software/ncurses-6.1 --with-cxx-shared
make && make install

2) 下载安装readline

wget http://ftp.gnu.org/gnu/readline/readline-8.0.tar.gz
tar zxvf readline-8.0.tar.gz
cd readline-8.0
./configure --prefix=/home/test/software/readline-8.0
make && make install

3) 下载安装zlib

wget https://www.zlib.net/zlib-1.2.13.tar.gz
tar zxvf zlib-1.2.13.tar.gz
cd zlib-1.2.13
./configure --prefix=/home/test/software/zlib-1.2.13
make && make install

4) 下载安装bzip2

wget https://nchc.dl.sourceforge.net/project/bzip2/bzip2-1.0.6.tar.gz
tar zxvf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
make PREFIX=/home/test/software/bzip2-1.0.6 install

5) 下载安装lzma

wget https://www.tukaani.org/xz/xz-5.2.4.tar.gz
tar zxvf xz-5.2.4.tar.gz
cd xz-5.2.4
./configure --prefix=/home/test/software/xz-5.2.4
make && make install

6) 下载安装pcre

wget https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz
tar zxvf pcre-8.45.tar.gz
cd pcre-8.45
./configure --prefix=/home/test/software/pcre-8.45 --enable-utf8
make && make install

7) 下载安装openssl

wget https://www.openssl.org/source/openssl-1.1.1d.tar.gz
tar zxvf openssl-1.1.1d.tar.gz
cd openssl-1.1.1d
./config --prefix=/home/test/software/openssl-1.1.1d
make && make install

8) 下载安装curl

wget https://curl.haxx.se/download/curl-7.66.0.tar.gz
tar zxvf curl-7.66.0.tar.gz
cd curl-7.66.0
./configure --prefix=/home/test/software/curl-7.66.0 --with-ssl=/home/test/software/openssl-1.1.1d
make && make install

9) 下载安装pcre2

wget https://sourceforge.net/projects/pcre/files/pcre2/10.36/pcre2-10.36.tar.gz
tar zxvf pcre2-10.36.tar.gz
cd pcre2-10.36
./configure --prefix=/home/test/software/pcre2-10.36
make && make install

3. 安装R

# 环境变量,针对依赖由非管理员用户编译安装的情况,直接执行即可
export LDFLAGS="-L/home/test/software/ncurses-6.1/lib -L/home/test/software/readline-8.0/lib -L/home/test/software/zlib-1.2.11/lib -L/home/test/software/bzip2-1.0.6/lib -L/home/test/software/xz-5.2.4/lib -L/home/test/software/pcre-8.43/lib -L/home/test/software/curl-7.66.0/lib -L/home/test/software/pcre2-10.36/lib"

export CPPFLAGS="-I/home/test/software/readline-8.0/include -I/home/test/software/zlib-1.2.11/include -I/home/test/software/bzip2-1.0.6/include -I/home/test/software/xz-5.2.4/include -I/home/test/software/pcre-8.43/include -I/home/test/software/curl-7.66.0/include -I/home/test/software/pcre2-10.36/include"

export CFLAGS="-I/home/test/software/readline-8.0/include -I/home/test/software/zlib-1.2.11/include -I/home/test/software/bzip2-1.0.6/include -I/home/test/software/xz-5.2.4/include -I/home/test/software/pcre-8.43/include -I/home/test/software/curl-7.66.0/include -I/home/test/software/pcre2-10.36/include"

# 如果curl是由非管理员用户编译安装的,则需要将此行添加到.bashrc或者.bash_profile中
export PATH=/home/test/software/curl-7.66.0/bin:$PATH

# 如果openssl是非管理员用户编译安装的,则需要此行添加到.bashrc或者.bash_profile中
export LD_LIBRARY_PATH=/home/test/software/openssl-1.1.1d/lib:$LD_LIBRARY_PATH

# 安装R
# 安装R-4.0.3需要换成https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/base/R-4/R-4.0.3.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/base/R-3/R-3.6.1.tar.gz
tar zxvf R-3.6.1.tar.gz
cd R-3.6.1
./configure --prefix=/home/test/software/R-3.6.1
make && make install

4. 错误解决

1) curl报错

错误信息:

  • configure: error: libcurl >= 7.22.0 library and headers are required with support for https

解决方法:

  • 编译安装curl时添加--with-ssl=/path/to/openssl
  • 环境变量添加export PATH=/path/to/curl/bin:$PATH
  • 环境变量添加export LD_LIBRARY_PATH=/path/to/openssl/lib:$LD_LIBRARY_PATH

注:
在确认curl已安装,且环境变量一切没问题的情况下,仍报此错误,可以尝试编辑configure文件,更改如下信息:

r_cv_have_curl722=no 改为 r_cv_have_curl722=yes
r_cv_have_curl_https=no 改为 r_cv_have_curl_https=yes

修改后可强行跳过curl验证步骤,仅供参考。

2) gcc-10.1.0下make报错

解决方法:

  • 改用gcc-6.4.0编译

3)pcre2报错

解决方法:

如果是R-4.0.3 configure报错

  • 环境变量添加export PKG_CONFIG_PATH=/path/to/pcre2-10.36/lib/pkgconfig:$PKG_CONFIG_PATH

如果是make报错

  • 环境变量添加export LD_LIBRARY_PATH=/path/to/pcre2-10.36/lib:$LD_LIBRARY_PATH

3) make时libiconv报错

错误信息:

  • undefined reference to `_libiconv_version'

解决方法:

# 编译安装libiconv
wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
tar zxvf libiconv-1.16.tar.gz
cd libiconv-1.16
./configure --prefix=/home/test/software/libiconv-1.16
make && make install

# 环境变量LDFLAGS加上-L/home/test/software/libiconv-1.16/lib
# 环境变量CFLAGS加上-I/home/test/software/libiconv-1.16/include
# 环境变量CPPFLAGS加上-I/home/test/software/libiconv-1.16/include

5. 其他

  • 目前本教程中绘图相关的库和X11库只能由管理员通过yum进行安装
  • 为防止对后续其他软件编译造成影响,本教程安装中使用的环境变量CFLAGS、CPPFLAGS和LDFLAGS应当注释或删除

你可能感兴趣的:(CentOS6 编译安装R-3.6.1 (更新R-4.0.3安装方法))