试图为某个开源项目做贡献。我尝试在网上寻找答案,也尝试了 Wikipedia 上的设置方法。但都不起作用。这让人很恼火。我需要提交我的工作。当我运行 git commit 时,我得到了以下结果:
please make sure JAVA_HOME is set to JDK8
现在,我使用 JAVA 11。我卸载了 JAVA 11,然后尝试安装 JAVA 8。没有成功,再次尝试安装 12,需要 JDK8。
echo $JAVA_HOME
给出
/usr/lib/jvm/java-12-oracle
java -version
是12.0.2
我想在我的计算机上安装 Java 8 和 Java 12。并经常在两者之间切换。我希望能够处理使用 Java 8 和 Java 12 的项目。
dpkg -L openjdk-8-jdk
给予
/.
/usr
/usr/lib
/usr/lib/jvm
/usr/lib/jvm/java-8-openjdk-amd64
/usr/lib/jvm/java-8-openjdk-amd64/bin
/usr/lib/jvm/java-8-openjdk-amd64/bin/appletviewer
/usr/lib/jvm/java-8-openjdk-amd64/bin/jconsole
/usr/lib/jvm/java-8-openjdk-amd64/include
/usr/lib/jvm/java-8-openjdk-amd64/include/jawt.h
/usr/lib/jvm/java-8-openjdk-amd64/include/linux
/usr/lib/jvm/java-8-openjdk-amd64/include/linux/jawt_md.h
/usr/lib/jvm/java-8-openjdk-amd64/lib
/usr/lib/jvm/java-8-openjdk-amd64/lib/jconsole.jar
/usr/lib/jvm/java-8-openjdk-amd64/man
/usr/lib/jvm/java-8-openjdk-amd64/man/ja_JP.UTF-8
/usr/lib/jvm/java-8-openjdk-amd64/man/ja_JP.UTF-8/man1
/usr/lib/jvm/java-8-openjdk-amd64/man/ja_JP.UTF-8/man1/appletviewer.1.gz
/usr/lib/jvm/java-8-openjdk-amd64/man/ja_JP.UTF-8/man1/jconsole.1.gz
/usr/lib/jvm/java-8-openjdk-amd64/man/man1
/usr/lib/jvm/java-8-openjdk-amd64/man/man1/appletviewer.1.gz
/usr/lib/jvm/java-8-openjdk-amd64/man/man1/jconsole.1.gz
/usr/share
/usr/share/doc
/usr/share/doc/openjdk-8-jre-headless
/usr/share/doc/openjdk-8-jre-headless/test-amd64
/usr/share/doc/openjdk-8-jre-headless/test-amd64/check-hotspot-hotspot.log.gz
/usr/share/doc/openjdk-8-jre-headless/test-amd64/check-jdk-hotspot.log.gz
/usr/share/doc/openjdk-8-jre-headless/test-amd64/check-langtools-hotspot.log.gz
/usr/share/doc/openjdk-8-jre-headless/test-amd64/failed_tests-hotspot.tar.gz
/usr/share/doc/openjdk-8-jre-headless/test-amd64/jtreg-summary-hotspot.log.gz
/usr/share/doc/openjdk-8-jre-headless/test-amd64/jtreport-hotspot.tar.gz
/usr/share/doc/openjdk-8-jdk
答案1
您可以使用“替代方案”在不同的 Java 版本之间切换:
sudo update-alternatives --config java
对于 Java 编译器也是如此(javac)如果你正在编译一些 Java 代码:
sudo update-alternatives --config javac
如果你通过 apt openjdk 安装了 Java 8:
sudo apt install openjdk-8-jdk
那么你的 java 主目录必须是:/usr/lib/jvm/java-8-openjdk-amd64
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
如果 Java 8 在更新替代方案你可以使用以下命令安装它:
update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-8-openjdk-amd64/bin/java 1000
然后用以下命令检查它是否存在:
update-alternatives --list java