A.8 源码安装

A.8.1 Ubuntu

  1. 首先启用源码仓库,否则执行 sudo apt-get build-dep r-base 会报如下错误
E: You must put some 'source' URIs in your sources.list
sudo sed -i -- 's/#deb-src/deb-src/g' /etc/apt/sources.list && sudo sed -i -- 's/# deb-src/deb-src/g' /etc/apt/sources.list
sudo apt-get update
  1. 安装编译 R 所需的系统依赖
sudo apt-get build-dep r-base-dev
  1. 编译安装 R
./configure
make && make install 
  1. 自定义编译选项
./configure --help

A.8.2 CentOS

基于 CentOS 7 和 GCC 4.8.5,参考 R-admin 手册

  • 下载源码包

    最新发布的稳定版

    curl -fLo ./R-latest.tar.gz https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/base/R-latest.tar.gz
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
     10 28.7M   10 3232k    0     0   107k      0  0:04:34  0:00:30  0:04:04  118k
  • 安装依赖

    sudo yum install -y yum-utils epel-release && sudo yum-builddep R-devel
    sudo dnf update && sudo dnf builddep R-devel # Fedora 30
  • 解压配置

    mkdir R-latest && tar -xzf ./R-latest.tar.gz -C ./R-latest && cd R-3.5.2
    
    ./configure --enable-R-shlib --enable-byte-compiled-packages \
      --enable-BLAS-shlib --enable-memory-profiling
    R is now configured for x86_64-pc-linux-gnu
    
      Source directory:          .
      Installation directory:    /usr/local
    
      C compiler:                gcc -std=gnu99  -g -O2
      Fortran 77 compiler:       gfortran  -g -O2
    
      Default C++ compiler:      g++   -g -O2
      C++98 compiler:            g++ -std=gnu++98 -g -O2
      C++11 compiler:            g++ -std=gnu++11 -g -O2
      C++14 compiler:
      C++17 compiler:
      Fortran 90/95 compiler:    gfortran -g -O2
      Obj-C compiler:            gcc -g -O2 -fobjc-exceptions
    
      Interfaces supported:      X11, tcltk
      External libraries:        readline, curl
      Additional capabilities:   PNG, JPEG, TIFF, NLS, cairo, ICU
      Options enabled:           shared R library, shared BLAS, R profiling, memory profiling
    
      Capabilities skipped:
      Options not enabled:
    
      Recommended packages:      yes
  • 编译安装

    make -j 2 all
    sudo make install
  • BLAS 加持(可选)

    BLAS 对于加快矩阵计算至关重要,编译 R 带 BLAS 支持,添加 OpenBLAS 支持 --with-blas="-lopenblas" 或 ATLAS 支持 --with-blas="-L/usr/lib64/atlas -lsatlas"

    sudo yum install -y openblas openblas-threads openblas-openmp 
    
    ./configure --enable-R-shlib --enable-byte-compiled-packages \
      --enable-BLAS-shlib --enable-memory-profiling \
      --with-blas="-lopenblas"
    R is now configured for x86_64-pc-linux-gnu
    
    Source directory:          .
    Installation directory:    /usr/local
    
    C compiler:                gcc -std=gnu99  -g -O2
    Fortran 77 compiler:       gfortran  -g -O2
    
    Default C++ compiler:      g++   -g -O2
    C++98 compiler:            g++ -std=gnu++98 -g -O2
    C++11 compiler:            g++ -std=gnu++11 -g -O2
    C++14 compiler:
    C++17 compiler:
    Fortran 90/95 compiler:    gfortran -g -O2
    Obj-C compiler:            gcc -g -O2 -fobjc-exceptions
    
    Interfaces supported:      X11, tcltk
    External libraries:        readline, **BLAS(OpenBLAS)**, curl
    Additional capabilities:   PNG, JPEG, TIFF, NLS, cairo, ICU
    Options enabled:           shared R library, shared BLAS, R profiling, memory profiling
    
    Capabilities skipped:
    Options not enabled:
    
    Recommended packages:      yes

    配置成功的标志,如 OpenBLAS

    checking for dgemm_ in -lopenblas... yes
    checking whether double complex BLAS can be used... yes
    checking whether the BLAS is complete... yes

    ATLAS 加持

    sudo yum install -y atlas
    ./configure --enable-R-shlib --enable-byte-compiled-packages \
      --enable-BLAS-shlib --enable-memory-profiling \
      --with-blas="-L/usr/lib64/atlas -lsatlas"
    R is now configured for x86_64-pc-linux-gnu
    
    Source directory:          .
    Installation directory:    /usr/local
    
    C compiler:                gcc -std=gnu99  -g -O2
    Fortran 77 compiler:       gfortran  -g -O2
    
    Default C++ compiler:      g++   -g -O2
    C++98 compiler:            g++ -std=gnu++98 -g -O2
    C++11 compiler:            g++ -std=gnu++11 -g -O2
    C++14 compiler:
    C++17 compiler:
    Fortran 90/95 compiler:    gfortran -g -O2
    Obj-C compiler:            gcc -g -O2 -fobjc-exceptions
    
    Interfaces supported:      X11, tcltk
    External libraries:        readline, **BLAS(generic)**, curl
    Additional capabilities:   PNG, JPEG, TIFF, NLS, cairo, ICU
    Options enabled:           shared R library, shared BLAS, R profiling, memory profiling
    
    Capabilities skipped:
    Options not enabled:
    
    Recommended packages:      yes

    ATLAS 配置成功

    checking for dgemm_ in -L/usr/lib64/atlas -lsatlas... yes
    checking whether double complex BLAS can be used... yes
    checking whether the BLAS is complete... yes

后续步骤同上