R 语言是广泛使用的统计学语言,用于统计学、生物信息学数据处理以及金融数据统计等方面。
本文就Ubuntu系统中安装R语言并配置Rstudio作为开发环境。
首先是安装R语言
先到CRAN清华大学的镜像中下载R语言的镜像(前面有些文献讲了通过apt-get进行安装)但是我们不使用这个方案,因此版本落后了。
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/R$ wget -c https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/base/R-3/R-3.5.1.tar.gz
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/R$ tar zxvf R-3.5.1.tar.gz
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/R$ cd R-3.5.1/
然后进行编译
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/R/R-3.5.1$ ./configure --enable-R-shlib=yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
loading site script './config.site'
loading build-specific script './config.site'
.......
.....
...
..
.
checking for cf77... no
checking for fort77... no
checking for fl32... no
checking for af77... no
checking for fc... no
configure: error: No F77 compiler found
在这个地方,发现有一个错误,查证了google后说要安装fortran77
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/R/R-3.5.0$ sudo apt-get install fort77
安装好了过后试一试configure,但是又出现一个问题:
checking for rl_callback_read_char in -lreadline... no
checking for main in -lncurses... no
checking for main in -ltermcap... no
checking for main in -ltermlib... no
checking for rl_callback_read_char in -lreadline... no
configure: error: --with-readline=yes (default) and headers/libs are not available
进一步安装这个就可以继续
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/R/R-3.5.0$ sudo apt-get install xorg-dev
接下来又会遇到的问题是:
configure: error: libcurl >= 7.22.0 library and headers are required with support for https
这个问题的解决方式是:
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/R/R-3.5.0$ sudo apt-get install libcurl4-gnutls-dev
最后遇到一个Warning
R is now configured for x86_64-pc-linux-gnu
Source directory: .
Installation directory: /usr/local
C compiler: gcc -g -O2
Fortran 77 compiler: f95 -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: g++ -std=gnu++14 -g -O2
C++17 compiler:
Fortran 90/95 compiler: gfortran -g -O2
Obj-C compiler:
Interfaces supported: X11
External libraries: readline, curl
Additional capabilities: PNG, JPEG, NLS
Options enabled: shared BLAS, R profiling
Capabilities skipped: TIFF, cairo, ICU
Options not enabled: memory profiling
Recommended packages: yes
configure: WARNING: you cannot build info or HTML versions of the R manuals
修复的方法是:
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/R/R-3.5.0$ sudo apt-get install texinfo
最后一次编译的结果是:
R is now configured for x86_64-pc-linux-gnu
Source directory: .
Installation directory: /usr/local
C compiler: gcc -g -O2
Fortran 77 compiler: f95 -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: g++ -std=gnu++14 -g -O2
C++17 compiler:
Fortran 90/95 compiler: gfortran -g -O2
Obj-C compiler:
Interfaces supported: X11
External libraries: readline, curl
Additional capabilities: PNG, JPEG, NLS
Options enabled: shared BLAS, R profiling
Capabilities skipped: TIFF, cairo, ICU
Options not enabled: memory profiling
Recommended packages: yes
这样就好了,继续往下走:
trying to compile and link a JNI program
detected JNI cpp flags :
detected JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
make[2]: Entering directory '/tmp/Rjavareconf.lrg0CW'
gcc -I"/home/yeyuntian/Software/R/R-3.5.0/include" -DNDEBUG -I/usr/local/include -fpic -g -O2 -c conftest.c -o conftest.o
conftest.c:1:17: fatal error: jni.h: No such file or directory
compilation terminated.
/home/yeyuntian/Software/R/R-3.5.0/etc/Makeconf:159: recipe for target 'conftest.o' failed
make[2]: *** [conftest.o] Error 1
make[2]: Leaving directory '/tmp/Rjavareconf.lrg0CW'
Unable to compile a JNI program
JAVA_HOME : /usr/lib/jvm/java-8-openjdk-amd64/jre
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /home/yeyuntian/Software/R/R-3.5.0
Done.
make[1]: Leaving directory '/home/yeyuntian/Software/R/R-3.5.0'
解决方法是更新安装jdk
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/R/R-3.5.0$ sudo apt-get install openjdk-8-*
然后make好了
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/R/R-3.5.0$ make check
以上步骤没有报错,但是在 make install 的时候就出现以下的问题了:
make: *** [install] Error 1
往上拉看看,有一个报错:
mkdir -p -- /usr/local/lib/R/doc
mkdir: cannot create directory ‘/usr/local/lib/R/doc’: Permission denied
Makefile:104: recipe for target 'installdirs' failed
因此这个报错是因为权限不够,我们加了一个权限试一试:
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/R/R-3.5.0$ sudo make install
OK,问题解决了!
R version 3.5.0 (2018-04-23) -- "Joy in Playing"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> q()
Save workspace image? [y/n/c]: y
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/R$ which R
/usr/local/bin/R
最后查验了以下,没有问题,因此我们就可以进一步进行我们的Rstudio的安装
Rstudio的安装与配置
我们在前面已经安装了R,接下来我们来安装Rstudio
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software$ mkdir Rstudio
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software$ l
code_1.27.2-1536736588_amd64.deb shadowsocksr-linux-client-CLI/ zotero/
R/ sogoupinyin_2.2.0.0108_amd64.deb
Rstudio/ texlive/
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software$ cd Rstudio/
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/Rstudio$ k
]k: command not found
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/Rstudio$ l
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/Rstudio$ wget -c https://download1.rstudio.org/rstudio-xenial-1.1.456-amd64.deb
--2018-10-09 01:46:50-- https://download1.rstudio.org/rstudio-xenial-1.1.456-amd64.deb
Connecting to 127.0.0.1:8118... connected.
Proxy request sent, awaiting response... 200 OK
Length: 68100044 (65M) [application/x-deb]
Saving to: ‘rstudio-xenial-1.1.456-amd64.deb’
然后进行安装
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/Rstudio$ sudo dpkg -i rstudio-xenial-1.1.456-amd64.deb
遇到了一个依赖问题
dpkg: dependency problems prevent configuration of rstudio:
rstudio depends on libjpeg62; however:
Package libjpeg62 is not installed.
通过apt-get -f 来解决
yeyuntian@yeyuntian-RESCUER-R720-15IKBN:~/Software/Rstudio$ sudo apt-get install -f
然后再进行一次 dpkg 的安装即可
最后的效果图:
OK,到此为止我们在Ubuntu下经过源码编译完成了R的安装以及Rstudio的安装