我正在尝试安装一些软件包(mailR),以便能够通过邮件将错误和消息传达给我的用户,并通过rJdbc连接到HIVE服务器,但是随着步骤的完成,安装rJava依赖关系变得越来越复杂。
第一个错误是要求rJava软件包,因此我尝试安装rJava:
install.packages("rJava") Installing package into ‘/home/joe/R/x86_64-pc-linux-gnu-library/3.6’ (as ‘lib’ is unspecified) trying URL 'https://cran.rstudio.com/src/contrib/rJava_0.9-11.tar.gz' Content type 'application/x-gzip' length 675188 bytes (659 KB) ================================================== downloaded 659 KB * installing *source* package ‘rJava’ ... ** package ‘rJava’ successfully unpacked and MD5 sums checked ** using staged installation checking for gcc... gcc -std=gnu99 checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc -std=gnu99 accepts -g... yes checking for gcc -std=gnu99 option to accept ISO C89... none needed checking how to run the C preprocessor... gcc -std=gnu99 -E checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for ANSI C header files... yes checking for sys/wait.h that is POSIX.1 compatible... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for string.h... (cached) yes checking sys/time.h usability... yes checking sys/time.h presence... yes checking for sys/time.h... yes checking for unistd.h... (cached) yes checking for an ANSI C-conforming const... yes checking whether time.h and sys/time.h may both be included... yes configure: checking whether gcc -std=gnu99 supports static inline... yes checking 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/lib/jvm/default-java/bin/java' archiver : '/usr/bin/jar' compiler : '/usr/bin/javac' header prep.: '/usr/bin/javah' cpp flags : '' java libs : '' configure: error: One or more Java configuration variables are not set. 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 ‘/home/jmvo/R/x86_64-pc-linux-gnu-library/3.6/rJava’ Warning in install.packages : installation of package ‘rJava’ had non-zero exit status The downloaded source packages are in ‘/tmp/RtmpkTvmz8/downloaded_packages’
因此,我按照root用户的指示进行了操作:
sudo R CMD javareconf Java interpreter : /usr/lib/jvm/default-java/bin/java Java version : 11.0.3 Java home path : /usr/lib/jvm/default-java Java compiler : /usr/bin/javac Java headers gen.: /usr/bin/javah Java archive tool: /usr/bin/jar trying to compile and link a JNI program detected JNI cpp flags : detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -fpic -g -O2 -fdebug-prefix-map=/build/r-base-VAQCff/r-base-3.6.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c conftest.c -o conftest.o conftest.c:1:10: fatal error: jni.h: No such file or directory #include^~~~~~~ compilation terminated. /usr/lib/R/etc/Makeconf:167: recipe for target 'conftest.o' failed make: *** [conftest.o] Error 1 Unable to compile a JNI program JAVA_HOME : /usr/lib/jvm/default-java Java library path: JNI cpp flags : JNI linker flags : Updating Java configuration in /usr/lib/R Done.
我检查了是否安装了Open JDK,因为许多SO答案似乎都与缺少JDK有关。
java -version openjdk version "1.8.0_212" OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03) OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)
可以肯定的是,尝试再次使用
sudo apt-get install openjdk-8-jdk Reading package lists... Done Building dependency tree Reading state information... Done openjdk-8-jdk is already the newest version (8u212-b03-0ubuntu1.18.04.1). 0 upgraded, 0 newly installed, 0 to remove and 74 not upgraded.
其他一些答案则建议通过apt-get这样安装rJava
sudo apt-get install r-cran-rjava Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: r-cran-rjava : Depends: r-api-3.4 E: Unable to correct problems, you have held broken packages.o
但是我使用的是R 3.6,因此不能选择返回。不能选择使用Oracle Java。许多可运行的应用程序都依赖于OpenJDK。
到目前为止没有成功。这是一个永无止境的过程。在此问题上尝试了许多SO答案都无济于事。我不仅需要rJava来发送邮件,还需要rJava上的许多其他过程,例如连接到Hive等等。
谢谢