我在安装最新版本的 R 时遇到问题,出现了一个我无法理解的错误“致命错误:jni.h:没有这样的文件或目录”。以下是我在安装 R 时出现错误之前所做的操作:
#download tar.gz file
https://cran.r-project.org/
#install because we need it for execution of "make"
sudo apt-get install libx11-dev
sudo apt-get install xorg-dev
sudo apt-get install libcurl4-openssl-dev
# decompile
# on terminal
./configure
make
安装库后,安装结束时我看到的是这个(无法粘贴所有内容,因为它太长了):
installing to /home/fafnyr/R/R-3.5.2/library/mgcv/libs
** R
** data
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (mgcv)
make[2]: Leaving directory '/home/fafnyr/R/R-3.5.2/src/library/Recommended'
make[1]: Leaving directory '/home/fafnyr/R/R-3.5.2/src/library/Recommended'
make[1]: Entering directory '/home/fafnyr/R/R-3.5.2/src/library'
building/updating vignettes for package 'grid' ...
building/updating vignettes for package 'parallel' ...
building/updating vignettes for package 'utils' ...
make[1]: Leaving directory '/home/fafnyr/R/R-3.5.2/src/library'
make[1]: Entering directory '/home/fafnyr/R/R-3.5.2'
configuring Java ...
Java interpreter : /usr/bin/java
Java version : 10.0.2
Java home path : /usr/lib/jvm/java-11-openjdk-amd64
Java compiler : not present
Java headers gen.:
Java archive tool:
trying to compile and link a JNI program
detected JNI cpp flags :
detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
make[2]: Entering directory '/tmp/Rjavareconf.VwU72a'
gcc -I"/home/fafnyr/R/R-3.5.2/include" -DNDEBUG -I/usr/local/include -fpic -g -O2 -c conftest.c -o conftest.o
conftest.c:1:10: fatal error: jni.h: No such file or directory
#include <jni.h>
^~~~~~~
compilation terminated.
/home/fafnyr/R/R-3.5.2/etc/Makeconf:162: recipe for target 'conftest.o' failed
make[2]: *** [conftest.o] Error 1
make[2]: Leaving directory '/tmp/Rjavareconf.VwU72a'
Unable to compile a JNI program
JAVA_HOME : /usr/lib/jvm/java-11-openjdk-amd64
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /home/fafnyr/R/R-3.5.2
Done.
make[1]: Leaving directory '/home/fafnyr/R/R-3.5.2'
答案1
对于这个问题,我找到了解决办法:
sudo apt install default-jdk
对于 makefile,我也遇到了一些问题,因此我安装了这个:
sudo apt-get install libx11-dev
sudo apt-get install xorg-dev
sudo apt-get install libcurl4-openssl-dev
此外,对于 3.5.2 的安装,我遵循那些指令:
安装通过 HTTPS 添加新存储库所需的软件包:
sudo apt install apt-transport-https software-properties-common
使用以下命令启用 CRAN 存储库并将 CRAN GPG 密钥添加到您的系统:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'
现在已添加存储库,请输入以下命令更新包列表并安装 R 包:
sudo apt update sudo apt install r-base
要验证安装是否成功,请运行以下命令,该命令将打印 R 版本:
R --version # or # sudo -i R