去年10月份曾经写过一个比较曲折的R安装教程,里面给自己加了很多戏,本以为有那篇教程在前,这下在阿里云上部署R会是一马平川,没想到还是踩了几个之前没踩过的坑,于是将这次的教训跟之前的教程整理一下,写一个比较干净的教程。如果你们想体会下之前我安装R的内心戏,可以看下这篇文章Linux下安装R(心路历程版)
这个教程主要分三个部分:1.主要库的准备;2.环境变量的配置;3.R主体的安装;4.其他可能遇到的问题及解决方案。
1. 主要库的准备
注:所有的builder文件夹都代表你的目标文件夹,你的库的源码的文件夹跟你要安装的目标文件夹最好分开
1.1安装zlib1.2.5版本及以上
1
2
3
4cd zlib-1.2.11
/export/app/src/zlib-1.2.11/configure --prefix =/export/app/zlib-1.2.11
make
make install
1.2安装bzip1
2
3
4cd bzip2-1.0.6
make -f Makefile-libbz2_so
修改Makefile 中的PREFIX=/export/app/bzip2-1.0.6
make && make install
1.3安装liblzma5.0.3版本及以上
1
2
3
4
5mkdir xz-5.2.3
cd xz-5.2.3
/export/app/src/xz-5.2.3/configure -prefix=/export/app/xz-5.2.3
make
make install
1.4安装pcre1
2
3
4
5mkdir pcre-8.42
cd pcre-8.42
/export/app/src/pcre-8.42/configure --prefix /export/app/pcre-8.42 --enable-utf --enable-unicode-properties --enable-jit --disable-cpp ##这个包的安装参数是有要求的,因此用的是官方文档的推荐命令
make
make install
1.5安装libcurl1
2
3
4
5
6tar -zxvf curl-7.28.0.tar.gz
mkdir curl-7.28.0
cd curl-7.28.0
/export/app/src/curl-7.28.0/configure --prefix=/export/app/curl-7.28.0
make
make install
1.6配置jdk
这个需要去官网下载适合你机器系统的版本,然后解压到相应文件夹。
2.及环境变量的配置
在~/.bash_profile
中加入如下环境变量:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37###zlib
export ver="zlib-1.2.11"
export C_INCLUDE_PATH="/export/app/${ver}/include:${C_INCLUDE_PATH}"
export LD_LIBRARY_PATH="/export/app/${ver}/lib:${LD_LIBRARY_PATH}"
export LIBRARY_PATH="${LD_LIBRARY_PATH}"
###curl
export ver="curl-7.28.0"
export C_INCLUDE_PATH="/export/app/${ver}/include:${C_INCLUDE_PATH}"
export LD_LIBRARY_PATH="/export/app/${ver}/lib:${LD_LIBRARY_PATH}"
export PATH="/export/app/${ver}/bin:${PATH}"
export LIBRARY_PATH="${LD_LIBRARY_PATH}"
###bzip
export ver="bzip2-1.0.6"
export C_INCLUDE_PATH="/export/app/${ver}/include:${C_INCLUDE_PATH}"
export LD_LIBRARY_PATH="/export/app/${ver}/lib:${LD_LIBRARY_PATH}"
export LIBRARY_PATH="${LD_LIBRARY_PATH}"
###pcre
export ver="pcre-8.42"
export C_INCLUDE_PATH="/export/app/${ver}/include:${C_INCLUDE_PATH}"
export LD_LIBRARY_PATH="/export/app/${ver}/lib:${LD_LIBRARY_PATH}"
export LIBRARY_PATH="${LD_LIBRARY_PATH}"
###xz
export ver="xz-5.2.3"
export C_INCLUDE_PATH="/export/app/${ver}/include:${C_INCLUDE_PATH}"
export LD_LIBRARY_PATH="/export/app/${ver}/lib:${LD_LIBRARY_PATH}"
export LIBRARY_PATH="${LD_LIBRARY_PATH}"
## Java_JRE
export ver="jdk1.8.0_161"
export JAVA_HOME="/export/app/jdk1.8.0_161"
export CLASSPATH="${JAVA_HOME}/lib/"
export PATH=${JAVA_HOME}/bin:${PATH}
然后重新登录一个bash,开始下一步安装R
.
3.安装R主体
1 | /export/app/src/R-3.4.4/configure --prefix=/export/app/R-3.4.4 --enable-R-shlib --with-cairo --with-jpeglib --with-readline --with-tcltk --with-blas --with-lapack --enable-R-profiling --with-x=no LDFLAGS="-L/export/app/bzip2-1.0.6/lib" CPPFLAGS="-I/export/app/bzip2-1.0.6/include" |
其中LDFLAGS
和CPPFLAGS
后面的路径要置换成你的bzip
包的安装路径。本来我们在第二部分里配置了这个库的环境变量的,但是不知道为什么这个不行。
然后1
2make
make install
这样就安装完成了,然后就可以将R
加入环境变量1
2
3
4## R
export ver="R-3.4.4"
export PATH="/export/app/${ver}/bin:$PATH"
export R_LIBS="/export/app/${ver}/library"
这样只要运行1
R
就会显示1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21$ R
R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
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.
>
4.可能的报错以及解决方法
4.1libcurl
的环境变量配置问题
报错:1
configure: error: libcurl >= 7.22.0 library and headers are required with support for https
在这里面有一个坑就是libcurl
在配置环境变量时一定要将bin
的路径也加入至环境变量,不然就会报错,而其他库则没有此要求。可以回头再看下3。
解决方法:将export PATH="/export/app/${ver}/bin:${PATH}"
加入环境变量,如下所示。1
2
3
4
5
6###curl
export ver="curl-7.28.0"
export C_INCLUDE_PATH="/export/app/${ver}/include:${C_INCLUDE_PATH}"
export LD_LIBRARY_PATH="/export/app/${ver}/lib:${LD_LIBRARY_PATH}"
export PATH="/export/app/${ver}/bin:${PATH}" ####就是它
export LIBRARY_PATH="${LD_LIBRARY_PATH}"
4.2jdk
版本不对
报错:1
/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
或1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17conftest.c:1:17: fatal error: jni.h: No such file or directory
^
compilation terminated.
make[2]: *** [conftest.o] Error 1
make[2]: Leaving directory `/tmp/Rjavareconf.xQ4EzH'
Unable to compile a JNI program
JAVA_HOME : /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.151.x86_64/jre
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /export/app/R-3.4.4
Done.
make[1]: Leaving directory `/export/app/R-3.4.4'
可能是64位系统装了32位的jdk或者
jdk版本不对,去官网重新下载适合自己的版本的
jdk`。
如果不知道你机器的版本,用下面这两个命令:1
2uname -a # 查看内核/操作系统/CPU信息
head -n 1 /etc/issue # 查看操作系统版本
比如我的结果是1
2.6.32-696.13.2.el6.x86_64
说明我应该下载64
位的jdk
。
4.3安装xlsx
等R包调用java
时报错1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25checking whether setjmp.h is POSIX.1 compatible... yes
checking whether sigsetjmp is declared... yes
checking whether siglongjmp is declared... yes
checking Java support in R... present:
interpreter : '/usr/bin/java'
archiver : ''
compiler : ''
header prep.: ''
cpp flags : ''
java libs : ''
configure: error: Java Development Kit (JDK) is missing or not registered in R
Make sure R is configured with full Java support (including JDK). Run
R CMD javareconf
as root to add Java support to R.
If you don't have root privileges, run
R CMD javareconf -e
to set all Java-related variables and then install rJava.
ERROR: configuration failed for package ‘rJava’
* removing ‘/export/app/R-3.4.4/library/rJava’
ERROR: dependency ‘rJava’ is not available for package ‘xlsxjars’
* removing ‘/export/app/R-3.4.4/library/xlsxjars’
ERROR: dependencies ‘rJava’, ‘xlsxjars’ are not available for package ‘xlsx’
* removing ‘/export/app/R-3.4.4/library/xlsx’
解决方案:同4.2点。
最后:如果你遇到了其他问题,欢迎你在评论里留下你的问题和报错代码,方便我完善这个文章,谢谢!