本文记录的是linux下R安装的心得,windows下的安装方法请自行google:
先说有root权限的时候:
官网上下载R源码:找到latest release 版本:R-3.5.1.tar.gz
https://mirrors.tuna.tsinghua.edu.cn/CRAN/
解压,进入路径
tar -zxvf R-3.5.1.tar.gz
cd R-3.5.1
./configure
有报错:
configure: error: --with-readline=yes (default) and headers/libs are not available
设置如下参数: ./configure --with-readline=no
或者centos系统:安装readline:yum install readline-devel
或者ubuntu系统:安装readline:
安装成功后继续./configure
又出现报错:
configure: error: --with-x=yes (default) and X11 headers/libs are not available
设置参数 --with-x=no
或者安装x:
yum install libX11-devel
yum install libXt-devel
继续
./configure --with-readline=no --with-x=no
还报错:没有装libzma
configure: error: "liblzma library and headers are required"
解决方法:
wget https://tukaani.org/xz/xz-5.2.4.tar.gz
tar -zxvf xz-5.2.4.tar.gz
cd xz-5.2.4/
./configure
make
make install
安装完成xz,无报错,再来继续编译R
./configure --with-readline=no --with-x=no
又报错:没有pcre
checking whether PCRE support suffices... configure: error: pcre >= 8.20 library and headers are required
解决方法:
wget https://nchc.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz
tar -zxvf pcre-8.42.tar.gz
cd pcre-8.42.tar.gz
./configure
make
make install
安装完成pcre,无报错,再来继续编译R
./configure --with-readline=no --with-x=no
又报错:没有libcurl
configure: error: libcurl >= 7.22.0 library and headers are required with support for https
解决方法:
wget https://curl.haxx.se/download/curl-7.61.0.tar.gz
tar -zxvf curl-7.61.0.tar.gz
cd curl-7.61.0/
./configure
make
make install
安装完成curl,无报错,再来继续编译R
./configure --with-readline=no --with-x=no
又报错:
configure: error: libcurl >= 7.22.0 library and headers are required with support for https
好像上一步的libcurl没有安装成功呐?奇怪,
仔细观察了一下,发现虽然是以root下载的,但是解压后的目录是以用户拥有的方式,于是
用sudo的方式试一次:
sudo ./configure
make
make install
安装完成,无报错
再来安装R
./configure --with-readline=no --with-x=no
报错:
configure: error: libcurl >= 7.22.0 library and headers are required with support for https
还是这个错。。。。。
已奔溃。。。
$ curl -V
curl 7.60.0 (x86_64-conda_cos6-linux-gnu) libcurl/7.60.0 OpenSSL/1.0.2o zlib/1.2.11
Release-Date: 2018-05-16
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP UnixSockets HTTPS-proxy
看版本,已经是7.60了呀。
有人说要下载libcurl-devel,
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/libcurl-devel-7.29.0-46.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/libcurl-7.29.0-46.el7.x86_64.rpm
rpm -ivh libcurl-devel-7.29.0-46.el7.x86_64.rpm libcurl-7.29.0-46.el7.x86_64.rpm
试了还是不行,最后。。。
用别的用户名登录,不用root登录
./configure --with-readline=no --with-x=no
···
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:
Interfaces supported:
External libraries: readline, curl
Additional capabilities: NLS
Options enabled: shared BLAS, R profiling
Capabilities skipped: PNG, JPEG, TIFF, cairo, ICU
Options not enabled: memory profiling
Recommended packages: yes
configure: WARNING: you cannot build info or HTML versions of the R manuals
configure: WARNING: you cannot build PDF versions of the R manuals
configure: WARNING: you cannot build PDF versions of vignettes and help pages
最后只有三个无关紧要的提醒。
赶紧
sudo make
输入了密码
sudo make install
成功了 但是使用时还是没有有问题,没有libR.so??
当没有安装bzip2时会报错如下:
checking whether bzip2 support suffices... configure: error: bzip2 library and headers are required
最后。。。
一怒之下删掉了安装了所有版本R,
rm -rf /usr/bin/R*
rm -rf /usr/local/bin/R*
删掉了安装的所有bzip2,
rm -rf /usr/local/bin/bz*
rm -rf /usr/local/include/bz*
yum remove bzip2
重新解压 bzip2
tar -zxvf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
make -f Makefile-libbz2_so
修改Makefile其中两行。
vi Makefile
CC=gcc -fPIC
CFLAGS=-Wall -fPIC -Winline -O2 -g $(BIGFILES)
然后
make
make install
然后安装R
将原来R解压的路径也删掉了
重新解压R包
tar -zxvf R-3.5.1.tar.gz
cd R-3.5.1
./configure --enable-R-shlib
居然没有报错
make
make install
都没有报错。。。。。。
重点来了
将R安装到指定路径下:在没有root权限时,我们只能安装在指定目录下。
要想安装到指定目录中则需要指定: --prefix=/path/to/install/
./configure --enable-R-shlib
,先根据报错将依赖的各种库都装上。安装时也要指定路径,一般情况下我会将其安装在解压后的该目录。
先后安装了zlib,bzip2,xz,curl.
然后编译的时候要加上LDFLAGS和CPPFLAGS相关的路径:
./configure --prefix=$HOME/Programme/R-3.3.1 --enable-R-shlib LDFLAGS="-L/$HOME/Programme/zlib-1.2.11/lib -L/$HOME/Programme/bzip2-1.0.6/lib -L/$HOME/Programme/xz-5.2.3/lib -L/$HOME/Programme/pcre-8.40/lib -L/$HOME/Programme/curl-7.52.1/lib" CPPFLAGS="-I/$HOME/Programme/zlib-1.2.11/include -I/$HOME/Programme/bzip2-1.0.6/include -I/$HOME/Programme/xz-5.2.3/include -I/$HOME/Programme/pcre-8.40/include -I/$HOME/Programme/curl-7.52.1/include"
然而还是会报错:
报错:
/usr/bin/ld: warning: libpcre.so.1, needed by ../../lib/libR.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: liblzma.so.5, needed by ../../lib/libR.so, not found (try using -rpath or -rpath-link)
../../lib/libR.so: undefined reference to `pcre_fullinfo'
../../lib/libR.so: undefined reference to `lzma_lzma_preset@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_alone_decoder@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_crc64@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_raw_encoder@XZ_5.0'
../../lib/libR.so: undefined reference to `pcre_config'
../../lib/libR.so: undefined reference to `lzma_code@XZ_5.0'
../../lib/libR.so: undefined reference to `lzma_stream_decoder@XZ_5.0'
../../lib/libR.so: undefined reference to `pcre_free'
../../lib/libR.so: undefined reference to `lzma_raw_decoder@XZ_5.0'
../../lib/libR.so: undefined reference to `pcre_free_study'
../../lib/libR.so: undefined reference to `pcre_assign_jit_stack'
../../lib/libR.so: undefined reference to `pcre_exec'
../../lib/libR.so: undefined reference to `lzma_version_string@XZ_5.0'
../../lib/libR.so: undefined reference to `pcre_maketables'
../../lib/libR.so: undefined reference to `lzma_stream_encoder@XZ_5.0'
../../lib/libR.so: undefined reference to `pcre_compile'
../../lib/libR.so: undefined reference to `pcre_study'
../../lib/libR.so: undefined reference to `pcre_version'
../../lib/libR.so: undefined reference to `lzma_end@XZ_5.0'
../../lib/libR.so: undefined reference to `pcre_jit_stack_alloc'
collect2: error: ld returned 1 exit status
make[3]: *** [R.bin] Error 1
make[3]: Leaving directory `/builder/software/R/src/main'
make[2]: *** [R] Error 2
make[2]: Leaving directory `/builder/software/R/src/main'
make[1]: *** [R] Error 1
make[1]: Leaving directory `/builder/software/R/src'
make: *** [R] Error 1
重点来了:
/usr/bin/ld: warning: libpcre.so.1, needed by ../../lib/libR.so, not found (try using -rpath or -rpath-link)
怎么会有这样的报错?编译的时候不是已经将这两个库的路径传入了呀?
一番搜索后,
有人提出
要添加动态库
#cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/opt/pcre-8.39/lib
/opt/xz-5.2.2/lib
然后执行
#ldconfig
但是我没有root权限啊,于是再一帆研究,根据报错提示,设置一下-rpath
看行不行。
修改Makeconf文件,再LDFLAGS这里加上了-Wl,-rpath
后面跟这两个库的路径,
LDFLAGS = -L/BIGDATA1/cygene_sydu_1/02.dropEst/zlib-1.2.11/lib -L/BIGDATA1/cygene_sydu_1/02.dropEst/bzip2-1.0.6/lib -L/BIGDATA1/cygene_sydu_1/02.dropEst/xz-5.2.4/lib -L/BIGDATA1/cygene_sydu_1/02.dropEst/pcre-8.42/lib -L/BIGDATA1/cygene_sydu_1/02.dropEst/curl-7.61.0/lib -Wl,-rpath=/BIGDATA1/cygene_sydu_1/02.dropEst/pcre-8.42/lib -Wl,-rpath=/BIGDATA1/cygene_sydu_1/02.dropEst/xz-5.2.4/lib
再进行make
,make install
就不会报错,完成安装。
或者在编译的时候直接将-Wl,-rpath=/
的路径跟在LDFLAGS里面,要写两次哦。
补充:
如果遇到如下报错
begin installing recommended package Matrix
ERROR: failed to lock directory ‘/BIGDATA1/cygene_sydu_1/software/R-3.5.1/library’ for modifying
Try removing ‘/BIGDATA1/cygene_sydu_1/software/R-3.5.1/library/00LOCK-Matrix’
make[2]: *** [Matrix.ts] Error 1
make[2]: Leaving directory `/BIGDATA1/cygene_sydu_1/software/R-3.5.1/src/library/Recommended'
make[1]: *** [recommended-packages] Error 2
make[1]: Leaving directory `/BIGDATA1/cygene_sydu_1/software/R-3.5.1/src/library/Recommended'
make: *** [stamp-recommended] Error 2
这里是开始安装某个package时失败了,那么想让它跳过,不安装就好了,在提示的报错信息中找到安装该package的路径,把里面的相应的package删掉即可,我这里删掉了Martrix包;
rm /BIGDATA1/cygene_sydu_1/software/R-3.5.1/src/library/Recommended/Matrix*
等R安装成功后再手动将这些包装上。
R 包的安装
R的package安装时遇到错误可以换镜像路径,举例如下:
install.packages("Rcpp",dependencies=TRUE, repos='http://cran.rstudio.com/')
install.packages("ggplot2",dependencies=TRUE, repos='http://cran.rstudio.com/')
R ggforce 包安装
install.packages("ggforce")
library(ggforce)
# geom_circle() 是来自ggforce这个包。用法跟ggplot一样:
ggplot(df.venn, aes(x0=x, y0=y, r= 1.5, fill = labels)) +
geom_circle(alpha=.3, size=1, colour='grey') +
coord_fixed() + theme_void()
关于bioconductor
R limma 包安装
source("http://www.bioconductor.org/biocLite.R")
biocLite("limma")
library(limma)
R tidyverse包安装
source("http://www.bioconductor.org/biocLite.R")
biocLite("tidyverse")
library(tidyverse)
其他包安装
source("[http://bioconductor.org/biocLite.R](http://bioconductor.org/biocLite.R)")
biocLite("ALL") 安装 ALL
biocLite("hgu95av2.db")
library(ALL)
library(hgu95av2.db)
总结:
Ubuntu下基本上可以通过安装这些库解决:
sudo apt-get install build-essential
sudo apt-get install fort77 (error)
sudo apt-get install xorg-dev
sudo apt-get install liblzma-dev libblas-dev gfortran
sudo apt-get install gcc-multilib
sudo apt-get install gobjc++ (error)
sudo apt-get install aptitude
sudo apt-get install libreadline-dev