经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » Linux/Shell » 查看文章
Linux 下 R 源码安装指南
来源:cnblogs  作者:章鱼猫先生  时间:2023/6/5 14:52:14  对本文有异议

?? 本文章同步自作者的语雀知识库,请点击这里阅读原文。

如果你使用的 Linux 系统 GCC 版本太低, 又没有 root 权限 (即使有 root 权限又担心升级 GCC 带来的风险) ; 同时你又不想入坑 conda, 但是你又希望安装一个最新版本的 R, 那么恭喜你, 这篇普通用户在 Linux 下源码编译安装 R 的记录刚好满足了你想要的一切.。

?? 说明

  1. 本文档以 R-3.6.0 为例, 但对于 R-3.6.x, R-4.0.x 的安装同样适用。
  2. 根据本教程,经过测试,以下版本均可以正常安装成功。
    • R-4.0.3
    • R-4.1.2
    • R-4.3.0

本教程在以下的安装环境中,经过测试都可以正常操作:

系统(版本) GCC 版本
Red Hat Enterprise Linux Server release 6.5 (Santiago), x86_64 gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
CentOS Linux release 7.6.1810 (Core), x86_64 gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
openEuler 20.03 (LTS) gcc (GCC) 7.3.0

1. 安装命令

R 源码编译安装基本命令。

  1. # Rpy:--enable-R-shlib
  2. # download list:https://mirrors.ustc.edu.cn/CRAN/src/base/
  3. $ wget https://mirrors.ustc.edu.cn/CRAN/src/base/R-3/R-3.6.0.tar.gz
  4. $ tar zxvf R-3.6.0.tar.gz
  5. $ cd R-3.6.0
  6. $ ./configure --prefix=/Bioinfo/SoftWare/R-3.6.0 --enable-R-shlib --enable-BLAS-shlib --with-blas --with-lapack

关于 R 相关的动态库:

  • R 编译的过程中,如果想要在其他语言中集成 R 就必须选择--enable-R-shlib选项,将 R 编译成 lib 模式,在此模式下,会生成 path-to-R/lib/libR.so库——将 R 编译成动态库(libR.so),然后 R 的执行程序与之链接;
    • 例如,如果不编译生成 libR.so,在安装 rpy2(Python 中的 R 语言接口模块) 时就无法正确编译。
  • 同时,确保同目录下 libRblas.so,libRlapack.so 两个链接库也被正确生成,这两个库默认会生成,如果没有,需要添加参数:--enable-BLAS-shlib,--with-blas,--with-lapack

2. 基础环境

  • configure: error: No Fortran compiler found
  1. # Ubuntu/Debian
  2. apt install gfortran
  3. # RHEL/openEluer
  4. yum install gcc-gfortran
  • configure: error: C++ preprocessor "/lib/cpp" fails sanity check
  1. # Ubuntu/Debian
  2. apt install build-essential
  3. apt install g++
  4. # RHEL/openEluer
  5. yum install glibc-headers
  6. yum install gcc-c++

3. 各种库和依赖解决

R 源码编译安装的时候需要的各种依赖库比较多,如果你有 root 的权限,建议使用 yum/apt 等系统命令解决;如果没有 root 权限,可以手动一个个去解决。

3.1 自动处理

针对 RHEL/Debian 一些常见的依赖,使用 yum/apt 自动解决的示例。

  • configure: error: --with-readline=yes (default) and headers/libs are not available
  1. # Ubuntu/Debian
  2. apt install install libreadline-dev
  3. # RHEL/openEluer
  4. yum install readline-devel
  • configure: error: --with-x=yes (default) and X11 headers/libs are not available
  1. # Ubuntu/Debian
  2. apt install libx11-dev xorg-dev libcurl4-openssl-dev
  3. # RHEL/openEluer
  4. yum install xorg-x11-server-devel libX11-devel libXt-devel
  • configure: error: "liblzma library and headers are required"
  1. # Ubuntu/Debian
  2. apt install liblzma-dev
  3. # RHEL/openEluer
  4. yum install lzma-devel xz xz-devel
  • configure: error: PCRE2 library and headers are required, or use --with-pcre1 and PCRE >= 8.32 with UTF-8 support
  1. # Ubuntu/Debian
  2. apt install libpcre2-dev
  3. # RHEL/openEluer
  4. yum install pcre pcre-devel # 安装 PCRE1
  5. yum install pcre2 pcre2-devel # 安装 PCRE2
  • configure: error: libcurl >= 7.28.0 library and headers are required with support for https
  1. # Ubuntu/Debian
  2. apt install libcurl4-openssl-dev
  3. # RHEL/openEluer
  4. yum install libcurl-devel

JPEG

R 安装过程中默认开启 --with-jpeglib(use jpeglib library (if available) [yes]),但是相关的依赖没有,依然可以正常安装(没有任何报错),但最后会提示:Capabilities skipped: JPEG!

  1. # Ubuntu/Debian
  2. yum install libjpeg-dev
  3. # RHEL/openEluer
  4. yum install libjpeg-devel

TIFF

R 安装过程中默认开启 --with-tifflib(use libtiff library (if available) [yes]),但是相关的依赖没有,依然可以正常安装(没有任何报错),但最后会提示:Capabilities skipped: TIFF!

  1. # Ubuntu/Debian
  2. yum install libtiff-dev
  3. # RHEL/openEluer
  4. yum install libtiff-devel

cairo

R 安装过程中默认开启 --with-cairo(use cairo (and pango) if available [yes]),但是相关的依赖没有,依然可以正常安装(没有任何报错),但最后会提示:Capabilities skipped: cairo!

  1. # Ubuntu/Debian
  2. apt install libcairo2-dev libxt-dev
  3. # RHEL/openEluer
  4. yum install cairo-devel

ICU

R 安装过程中默认开启 --with-ICU(use ICU library (if available) [yes]),如果不可用,最后会提示:Capabilities skipped: ICU!

  1. # Ubuntu/Debian
  2. apt install libicu-dev
  3. # RHEL/openEluer
  4. yum install libicu libicu-devel

3.2 手动处理

以下是一些常见的依赖手动解决的示例,可以参考。

zlib

根据《R Installation and Administration: A.1 Essential programs and libraries》官方文档,zlib (version 1.2.5 or later),至少需要 1.2.5 及以上版本。

Installations ofzlib(version 1.2.5 or later), libbz2(version 1.0.6 or later: called bzip2-libs/bzip2-devel or libbz2-1.0/libbz2-dev by some Linux distributions) andliblzmaversion 5.0.3 or later are required.

  1. 报错:
  2. checking for zlib.h... yes
  3. checking if zlib version >= 1.2.5... no
  4. checking whether zlib support suffices... configure: error: zlib library and headers are required
  5. ## 缺少zlib或者zlib版本过低, 要求 zlib 版本 >= 1.2.5
  1. # download list:http://www.zlib.net/fossils/
  2. $ wget http://www.zlib.net/fossils/zlib-1.2.6.tar.gz
  3. $ tar xvf zlib-1.2.6.tar.gz
  4. $ cd zlib-1.2.6
  5. $ ./configure --prefix=/Bioinfo/SoftWare/NewLibs/zlib-1.2.6
  6. $ make && make install

接着安装 R-3.6.0:

  1. $ cd ../R-3.6.0
  2. $ ./configure --prefix=/Bioinfo/SoftWare/R-3.6.0 --enable-R-shlib LDFLAGS="-L/Bioinfo/SoftWare/NewLibs/zlib-1.2.6/lib" CPPFLAGS="-I/Bioinfo/SoftWare/NewLibs/zlib-1.2.6/include"
  3. 报错:
  4. checking for zlib.h... yes
  5. checking if zlib version >= 1.2.5... yes
  6. checking whether zlib support suffices... yes
  7. checking mmap support for zlib... yes
  8. checking for BZ2_bzlibVersion in -lbz2... yes
  9. checking bzlib.h usability... yes
  10. checking bzlib.h presence... yes
  11. checking for bzlib.h... yes
  12. checking if bzip2 version >= 1.0.6... no
  13. checking whether bzip2 support suffices... configure: error: bzip2 library and headers are required
  14. ## zlib 版本已经符合要求,bzip2 版本要求 >= 1.0.6

bzip2 or libbz2

根据《R Installation and Administration: A.1 Essential programs and libraries》官方文档, libbz2 (version 1.0.6 or later: called bzip2-libs/bzip2-devel or libbz2-1.0/libbz2-dev by some Linux distributions),至少需要 1.0.6 及以上版本.

  1. $ wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
  2. $ tar zvxf bzip2-1.0.6.tar.gz
  3. $ cd bzip2-1.0.6
  4. $ make -f Makefile-libbz2_so
  5. $ make clean
  6. $ make
  7. $ make install PREFIX=/Bioinfo/SoftWare/NewLibs/bzip2-1.0.6

重新安装 R-3.6.0:

  1. $ cd ../R-3.6.0
  2. $ ./configure --prefix=/Bioinfo/SoftWare/R-3.6.0 --enable-R-shlib LDFLAGS="-L/Bioinfo/SoftWare/NewLibs/zlib-1.2.6/lib -L/Bioinfo/SoftWare/NewLibs/bzip2-1.0.6/lib" CPPFLAGS="-I/Bioinfo/SoftWare/NewLibs/zlib-1.2.6/include -I/Bioinfo/SoftWare/NewLibs/bzip2-1.0.6/include"
  3. 报错:
  4. checking if bzip2 version >= 1.0.6... yes
  5. checking whether bzip2 support suffices... yes
  6. checking for lzma_version_number in -llzma... yes
  7. checking lzma.h usability... yes
  8. checking lzma.h presence... yes
  9. checking for lzma.h... yes
  10. checking if lzma version >= 5.0.3... yes
  11. checking for pcre_fullinfo in -lpcre... no
  12. checking whether PCRE support suffices... configure: error: pcre >= 8.10 library and headers are required
  13. ## 要求 pcre >= 8.10 (同时要求 pcre < 10.0, 否则再次安装 R-3.6.0 时报错)
  14. # 安装 pcre-8.12,configure 编译 R-3.6.0 时报错:
  15. checking for pcre/pcre.h... no
  16. checking if PCRE version >= 8.10, < 10.0 and has UTF-8 support... no
  17. checking whether PCRE support suffices... configure: error: pcre >= 8.10 library and headers are required
  18. # PCRE 安装需要 --enable-utf8,同时版本 >= 8.10 且 < 10.0

PCRE

在《R Installation and Administration: A.1 Essential programs and libraries》官方文档中要求, PCRE 版本最好在 8.32 及以上.

Either PCRE1 (version 8.32 or later, formerly known as just PCRE) or PCRE2 is required: PCRE2 is preferred and using PCRE1 requires configure option --with-pcre1. Only the 8-bit library and headers are needed if these are packaged separately. JIT support (optional) is desirable for the best performance. For PCRE2 >= 10.30 (which is desirable as matching has been re-written not to use recursion and the Unicode tables were updated to version 10).

  1. # 源码安装 PCRE1
  2. $ wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz --no-check-certificate
  3. $ tar zvxf pcre-8.40.tar.gz
  4. $ cd pcre-8.40
  5. $ ./configure --prefix=/Bioinfo/SoftWare/NewLibs/pcre-8.40 --enable-utf8
  6. $ make -j3 && make install
  7. # root 安装 PCRE1
  8. yum install pcre pcre-devel
  9. # 源码的方式安装 PCRE2,这里不介绍,跟源码安装 PCRE1 原理是一样的,自己去谷歌就好
  10. # root 安装 PCRE2
  11. yum install pcre2 pcre2-devel

注意:

  1. R-3.4.2 要求 pcre 版本(>= 8.20, < 10.0);
  2. R-4.0.1 要求 PCRE >= 8.32 with UTF-8 support;
  3. configure: error: PCRE2 library and headers are required, or use --with-pcre1 and PCRE >= 8.32 with UTF-8 support。R-4.0 以上在 configure 时,需要增加一个 --with-pcre1 参数;或者安装 PCRE2!

重新安装 R-3.6.0:

  1. $ cd ../R-3.6.0
  2. $ ./configure --prefix=/Bioinfo/SoftWare/R-3.6.0 --enable-R-shlib LDFLAGS="-L/Bioinfo/SoftWare/NewLibs/zlib-1.2.6/lib -L/Bioinfo/SoftWare/NewLibs/bzip2-1.0.6/lib -L/Bioinfo/SoftWare/NewLibs/pcre-8.40/lib" CPPFLAGS="-I/Bioinfo/SoftWare/NewLibs/zlib-1.2.6/include -I/Bioinfo/SoftWare/NewLibs/bzip2-1.0.6/include -I/Bioinfo/SoftWare/NewLibs/pcre-8.40/include"
  3. 报错:
  4. checking curl/curl.h usability... yes
  5. checking curl/curl.h presence... yes
  6. checking for curl/curl.h... yes
  7. checking if libcurl is version 7 and >= 7.28.0... no
  8. configure: error: libcurl >= 7.28.0 library and headers are required with support for https
  9. # 需要安装 curl >= 7.28.0

curl or libcurl

在《R Installation and Administration: A.1 Essential programs and libraries》要求, libcurl 大于或等于 7.22.0 版本。Library libcurl (version 7.22.0 or later) is required, with at least 7.28.0 being desirable.

  1. $ wget https://curl.haxx.se/download/curl-7.64.1.tar.gz --no-check-certificate
  2. $ tar zvxf curl-7.64.1.tar.gz
  3. $ cd curl-7.64.1
  4. ## 不指定证书
  5. $ ./configure --prefix=/Bioinfo/SoftWare/NewLibs/curl-7.64.1
  6. ## 指定证书(推荐)
  7. $ wget https://curl.haxx.se/ca/cacert.pem -O /Bioinfo/SoftWare/certs/ca-bundle.crt --no-check-certificate
  8. $ ./configure --prefix=/Bioinfo/SoftWare/NewLibs/curl-7.64.1 --with-ca-bundle=/Bioinfo/SoftWare/certs/ca-bundle.crt
  9. $ make
  10. $ make install

如果你有管理员的权限,你也可以使用 root 的方法直接安装 libcurl:

  1. # CentOS 7.6 自带的 libcurl 最新版本应该是 7.29.0-59.el7_9.1
  2. yum install libcurl libcurl-devel

注意:

  1. 有些情况下,R 在链接一些在线数据库,或者下载某些特殊包时,可能导致 SSL certificate problem: unable to get local issuer certificate 异常,这种情况可以通过 --with-ca-bundle 指定证书来解决。
  2. 参考下面的内容。

R 语言关于 SSL 证书异常处理笔记

重新安装 R-3.6.0:

  1. $ ./configure --prefix=/Bioinfo/SoftWare/R-3.6.0 --enable-R-shlib LDFLAGS="-L/Bioinfo/SoftWare/NewLibs/zlib-1.2.6/lib -L/Bioinfo/SoftWare/NewLibs/bzip2-1.0.6/lib -L/Bioinfo/SoftWare/NewLibs/pcre-8.40/lib -L/Bioinfo/SoftWare/NewLibs/curl-7.64.1/lib" CPPFLAGS="-I/Bioinfo/SoftWare/NewLibs/zlib-1.2.6/include -I/Bioinfo/SoftWare/NewLibs/bzip2-1.0.6/include -I/Bioinfo/SoftWare/NewLibs/pcre-8.40/include -I/Bioinfo/SoftWare/NewLibs/curl-7.64.1/include"
  2. $ make
  3. 报错:
  4. /Bioinfo/SoftWare/NewLibs/bzip2-1.0.6/lib/libbz2.a: could not read symbols: Bad value
  5. collect2: ld returned 1 exit status
  6. make[3]: *** [libR.so] Error 1
  7. make[3]: Leaving directory `/home/shenweiyan/inst/R-3.6.0/src/main'
  8. make[2]: *** [R] Error 2
  9. make[2]: Leaving directory `/home/shenweiyan/inst/R-3.6.0/src/main'
  10. make[1]: *** [R] Error 1
  11. make[1]: Leaving directory `/home/shenweiyan/inst/R-3.6.0/src'
  12. make: *** [R] Error 1
  13. # 需要使用64位元的方法重新编译 bzip2

重装 bzip2-1.0.6, 如下所示, 首先修改 bzip2-1.0.6 的 Makefile 文件:

  1. CC=gcc -fPIC
  2. AR=ar
  3. RANLIB=ranlib
  4. LDFLAGS=
  5. BIGFILES=-D_FILE_OFFSET_BITS=64

然后, 重新编译 bzip2-1.0.6:

  1. $ make clean
  2. $ make
  3. $ make install PREFIX=/Bioinfo/SoftWare/NewLibs/bzip2-1.0.6

liblzma

在编译过程中发现: "configure: error: "liblzma library and headers are required", 需要安装 xz, 对应主页: https://tukaani.org/xz/, 安装如下:

  1. $ wget https://nchc.dl.sourceforge.net/project/lzmautils/xz-5.2.3.tar.gz
  2. $ tar zvxf xz-5.2.3.tar.gz
  3. $ cd xz-5.2.3/
  4. $ ./configure --prefix=/Bioinfo/SoftWare/NewLibs/xz-5.2.3
  5. $ make -j3
  6. $ make install

libtiff

R shell 中使用 capabilities() 可以查看 R 已经编译支持的功能, 对于画图可以增加下面几个参数, 使 R 支持对应格式的图片保存, 与此同时要确保对应库已经安装.

  1. --with-cairo use cairo (and pango) if available [yes]
  2. --with-libpng use libpng library (if available) [yes]
  3. --with-jpeglib use jpeglib library (if available) [yes]
  4. --with-libtiff use libtiff library (if available) [yes]

以 tiff 为例, 需要安装 libtiff 库:

The bitmapped graphics devices jpeg(), png() and tiff() need the appropriate headers and libraries installed: jpeg (version 6b or later, or libjpeg-turbo) or libpng (version 1.2.7 or later) and zlib or libtiff(versions 4.0.[5-10] have been tested) respectively.

  1. $ wget ftp://download.osgeo.org/libtiff/tiff-4.0.9.zip
  2. $ unzip tiff-4.0.9.zip
  3. $ cd tiff-4.0.9
  4. $ ./configure --prefix=/Bioinfo/SoftWare/NewLibs/tiff-4.0.9
  5. $ make
  6. $ make install

如果你有管理员权限,你也可以直接使用 root 直接安装 libtiff:

  1. # CentOS 7.6 自带的 libcurl 最新版本应该是 4.0.3-35.el7
  2. yum install libtiff libtiff-devel

然后重新编译 R-3.6.0:

  1. $ ./configure --prefix=/Bioinfo/SoftWare/R-3.6.0 --enable-R-shlib --with-libtiff LDFLAGS="-L/Bioinfo/SoftWare/NewLibs/tiff-4.0.9/lib" CPPFLAGS="-I/Bioinfo/SoftWare/NewLibs/tiff-4.0.9/include"

如果 tiff 无法使用, 可以考虑在 ~/.bashrc 中添加 libtiff 库路径, 然后重新再编译 R .

  1. export LD_LIBRARY_PATH=/Bioinfo/SoftWare/NewLibs/tiff-4.0.9/lib:$LD_LIBRARY_PATH
  2. export PKG_CONFIG_PATH=/Bioinfo/SoftWare/NewLibs/tiff-4.0.9/lib/pkgconfig:$PKG_CONFIG_PATH

libjpeg and libpng16

R 安装完以后, 使用 plot 进行画图, 如果出现如下错误:

  1. > plot(1:0)
  2. Error in (function (display = "", width, height, pointsize, gamma, bg, :
  3. X11 module cannot be loaded
  4. In addition: Warning message:
  5. In (function (display = "", width, height, pointsize, gamma, bg, :
  6. unable to load shared object '/Bioinfo/SoftWare/R-3.6.0/lib64/R/modules//R_X11.so':
  7. libjpeg.so.9: cannot open shared object file: No such file or directory
  8. > quit()
  9. Save workspace image? [y/n/c]: n

使用 ldd 命令如果看到 libjpeg.so.9、libpng16.so.16 not found,则可以考虑手动安装这两个包:

  1. $ /Bioinfo/SoftWare/R-3.6.0/bin/R CMD ldd /Bioinfo/SoftWare/R-3.6.0/lib64/R/modules//R_X11.so
  2. linux-vdso.so.1 => (0x00007fff3c79b000)
  3. libtiff.so.5 => /Bioinfo/SoftWare/NewLibs/tiff-4.0.9/lib/libtiff.so.5 (0x00007f75369dc000)
  4. libjpeg.so.9 => not found
  5. libpng16.so.16 => not found
  6. libpangocairo-1.0.so.0 => /usr/lib64/libpangocairo-1.0.so.0 (0x00007f75367ba000)
  7. libpango-1.0.so.0 => /usr/lib64/libpango-1.0.so.0 (0x00007f753656e000)
  8. libgobject-2.0.so.0 => /lib64/libgobject-2.0.so.0 (0x00007f7536322000)
  9. ......

libjpeg.so.9, libpng16.so.16 安装步骤如下:

  1. $ wget http://www.ijg.org/files/jpegsrc.v9c.tar.gz
  2. $ tar zvxf jpegsrc.v9c.tar.gz
  3. $ cd jpeg-9c
  4. $ ./configure --prefix=/Bioinfo/SoftWare/NewLibs/jpeg-9c
  5. $ make
  6. $ make install
  7. $ wget https://download.sourceforge.net/libpng/libpng-1.6.37.tar.gz
  8. $ tar zvxf libpng-1.6.37.tar.gz
  9. $ cd libpng-1.6.37
  10. $ ./configure --prefix=/Bioinfo/SoftWare/NewLibs/libpng-1.6.37
  11. $ make
  12. $ make install

4. 完整编译安装命令

如果使用了自定义安装的 gcc/c++ 进行编译, 需要在 configure 时候使用 CC/CXX 进行指定, 否则使用系统默认的 gcc/c++,由于 CentOS-6.5 默认的 gcc==4.4.7, 该版本的 gcc 会导致 R>=3.5.0 编译出现各种错误,非 root 用户手动升级 gcc 可以参考:
非 root 用户手动编译安装 GCC

最后,CentOS 下 R 源码安装的完整 configure 命令如下(同样适用于 Ubuntu/Debian):

  1. # 粘贴到命令行时,请把 \ 去掉,连成一行命令再回车执行
  2. $ ./configure --prefix=/Bioinfo/SoftWare/R-3.6.0 CC=/Bioinfo/SoftWare/gcc-4.8.5/bin/gcc CXX=/Bioinfo/SoftWare/gcc-4.8.5/bin/c++ --enable-R-shlib --with-libtiff --with-libpng --with-jpeglib --with-x --with-cairo --with-pcre1 LDFLAGS="-L/Bioinfo/SoftWare/NewLibs/zlib-1.2.6/lib -L/Bioinfo/SoftWare/NewLibs/bzip2-1.0.6/lib \
  3. -L/Bioinfo/SoftWare/NewLibs/pcre-8.40/lib \
  4. -L/Bioinfo/SoftWare/NewLibs/curl-7.64.1/lib -L/Bioinfo/SoftWare/NewLibs/tiff-4.0.9/lib -L/Bioinfo/SoftWare/NewLibs/jpeg-9c/lib -L/Bioinfo/SoftWare/NewLibs/libpng-1.6.37/lib" \
  5. CPPFLAGS="-I/Bioinfo/SoftWare/NewLibs/zlib-1.2.6/include \
  6. -I/Bioinfo/SoftWare/NewLibs/bzip2-1.0.6/include \
  7. -I/Bioinfo/SoftWare/NewLibs/pcre-8.40/include -I/Bioinfo/SoftWare/NewLibs/curl-7.64.1/include -I/Bioinfo/SoftWare/NewLibs/tiff-4.0.9/include -I/Bioinfo/SoftWare/NewLibs/jpeg-9c/include -I/Bioinfo/SoftWare/NewLibs/libpng-1.6.37/include"
  8. # configure 的所有配置信息,都会保存在 ./Makeconf 文件中
  9. checking build system type... x86_64-pc-linux-gnu
  10. checking host system type... x86_64-pc-linux-gnu
  11. loading site script './config.site'
  12. ......
  13. config.status: executing libtool commands
  14. config.status: executing stamp-h commands
  15. R is now configured for x86_64-pc-linux-gnu
  16. Source directory: .
  17. Installation directory: /Bioinfo/SoftWare/R-3.6.0
  18. C compiler: gcc -std=gnu99 -g -O2
  19. Fortran fixed-form compiler: gfortran -g -O2
  20. Default C++ compiler: g++ -std=gnu++11 -g -O2
  21. C++14 compiler:
  22. C++17 compiler:
  23. C++20 compiler:
  24. Fortran free-form compiler: gfortran -g -O2
  25. Obj-C compiler:
  26. Interfaces supported: X11, tcltk
  27. External libraries: pcre2, readline, curl
  28. Additional capabilities: PNG, JPEG, TIFF, NLS, cairo, ICU
  29. Options enabled: shared R library, shared BLAS, R profiling
  30. Capabilities skipped:
  31. Options not enabled: memory profiling
  32. Recommended packages: yes
  33. configure: WARNING: you cannot build info or HTML versions of the R manuals
  34. configure: WARNING: neither inconsolata.sty nor zi4.sty found: PDF vignettes and package manuals will not be rendered optimally

注意:

  • --with-x--with-cairo 是开启 X11 图形化的参数,应该增加一下。
  • R-4.0 以上需要增加一个 --with-pcre1 参数,或者直接使用 PCRE2。
  • 最后关于 HTML 的 WARNING 不会影响 R 的安装和使用,可以忽略。

最后,使用 make 和 make install 完成安装。

  1. $ make
  2. $ make install

5. 设置环境变量

最后, 把安装完成的 R 添加至环境变量:

  1. export R_HOME=path-to-R
  2. export R_LIBS=$R_HOME/lib64/R/library
  3. export LD_LIBRARY_PATH=$R_HOME/lib:$LD_LIBRARY_PATH
  4. export PATH=$R_HOME/bin:$PATH
  • R_LIBS 的作用是 python 的 rpy2 调用安装的 R 包时,根据该变量寻找对应的包;
  • LD_LIBRARY_PATH 则是相关动态依赖库需要查找的路径;
  • 环境变量设置中比较容易漏掉的是 PATHLD_LIBRARY_PATH,如果是用 root 安装,可能会没有问题,如果安装到个人目录下,不添加这两个变量的话,就无法正确寻找需要的动态链接库,如下:
  1. $ python
  2. Python 2.7.14 (default, Mar 9 2018, 08:39:17)
  3. [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> import rpy2
  6. >>> import rpy2.robjects as robjects
  7. Error: package or namespace load failed for stats in dyn.load(file, DLLpath = DLLpath, ...):
  8. unable to load shared object '/Bioinfo/SoftWare/R-3.6.0/lib64/R/library/stats/libs/stats.so':
  9. libRlapack.so: cannot open shared object file: No such file or directory
  10. During startup - Warning message:
  11. package stats in options("defaultPackages") was not found
  12. >>> robjects.r('library(splines)')
  13. Error: package or namespace load failed for splines in dyn.load(file, DLLpath = DLLpath, ...):
  14. unable to load shared object '/Bioinfo/SoftWare/R-3.6.0/lib64/R/library/stats/libs/stats.so':
  15. libRlapack.so: cannot open shared object file: No such file or directory
  16. Traceback (most recent call last):
  17. File "<stdin>", line 1, in <module>
  18. File "/Bioinfo/SoftWare/Python-2.7.14/lib/python2.7/site-packages/rpy2/robjects/__init__.py", line 269, in __call__
  19. res = self.eval(p)
  20. File "/Bioinfo/SoftWare/Python-2.7.14/lib/python2.7/site-packages/rpy2/robjects/functions.py", line 170, in __call__
  21. return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
  22. File "/Bioinfo/SoftWare/Python-2.7.14/lib/python2.7/site-packages/rpy2/robjects/functions.py", line 100, in __call__
  23. res = super(Function, self).__call__(*new_args, **new_kwargs)
  24. rpy2.rinterface.RRuntimeError: Error: package or namespace load failed for splines in dyn.load(file, DLLpath = DLLpath, ...):
  25. unable to load shared object '/Bioinfo/SoftWare/R-3.6.0/lib64/R/library/stats/libs/stats.so':
  26. libRlapack.so: cannot open shared object file: No such file or directory
  1. $ ldd /Bioinfo/SoftWare/R-3.6.0/lib64/R/library/stats/libs/stats.so
  2. linux-vdso.so.1 => (0x00007fffd65ba000)
  3. libRlapack.so => not found
  4. libRblas.so => not found
  5. libgfortran.so.3 => /lib64/libgfortran.so.3 (0x00007fed38cbb000)
  6. libm.so.6 => /lib64/libm.so.6 (0x00007fed389b9000)
  7. libquadmath.so.0 => /lib64/libquadmath.so.0 (0x00007fed3877c000)
  8. libR.so => not found
  9. libgomp.so.1 => /lib64/libgomp.so.1 (0x00007fed38556000)
  10. libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fed38339000)
  11. libc.so.6 => /lib64/libc.so.6 (0x00007fed37f76000)
  12. libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fed37d60000)
  13. /lib64/ld-linux-x86-64.so.2 (0x00005561aa2c3000)

解决方法:

  1. $ export LD_LIBRARY_PATH="/Bioinfo/SoftWare/R-3.6.0/lib64/R/lib:$LD_LIBRARY_PATH"
  2. $ ldd /Bioinfo/SoftWare/R-3.5.0/lib64/R/library/stats/libs/stats.so
  3. linux-vdso.so.1 => (0x00007ffd0f3af000)
  4. libRlapack.so => /Bioinfo/SoftWare/R-3.6.0/lib64/R/lib/libRlapack.so (0x00007f6509c47000)
  5. libRblas.so => /Bioinfo/SoftWare/R-3.6.0/lib64/R/lib/libRblas.so (0x00007f6509a19000)
  6. libgfortran.so.3 => /lib64/libgfortran.so.3 (0x00007f65096ee000)
  7. libm.so.6 => /lib64/libm.so.6 (0x00007f65093ec000)
  8. libquadmath.so.0 => /lib64/libquadmath.so.0 (0x00007f65091af000)
  9. libR.so => /Bioinfo/SoftWare/R-3.6.0/lib64/R/lib/libR.so (0x00007f6508b81000)
  10. libgomp.so.1 => /lib64/libgomp.so.1 (0x00007f650895b000)
  11. libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f650873e000)
  12. libc.so.6 => /lib64/libc.so.6 (0x00007f650837b000)
  13. libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f6508165000)
  14. /lib64/ld-linux-x86-64.so.2 (0x000055583c2da000)
  15. libreadline.so.6 => /lib64/libreadline.so.6 (0x00007f6507f1e000)
  16. libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f6507cbc000)
  17. liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f6507a96000)
  18. libbz2.so.1 => /lib64/libbz2.so.1 (0x00007f6507885000)
  19. libz.so.1 => /lib64/libz.so.1 (0x00007f650766f000)
  20. librt.so.1 => /lib64/librt.so.1 (0x00007f6507467000)
  21. libdl.so.2 => /lib64/libdl.so.2 (0x00007f6507262000)
  22. libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007f6507038000)

以上就是普通用户源码编译安装最新版本 R 的全部内容, 总的一句话就是缺什么安装什么, 从最基本的 gcc 编译器开始到 R 所需要的各种依赖库,直至最终安装完成.。

6. 参考资料

原文链接:https://www.cnblogs.com/shenweiyan/p/17457243.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号