如何以 ubuntu 方式降级 java(jre)

如何以 ubuntu 方式降级 java(jre)

问题的背景是我曾尝试(徒劳地)将 Java 9 与 Eclipse Oxygen 一起设置我新安装的盒子。

它们不能一起工作(关于这一点有多个问题,而且看起来每个问题都是具有不同原因的特殊情况)。

直接原因似乎是 Eclipse(eclipse.ini)无法启动 JVM,并且带有参数的弹出窗口甚至无法复制和粘贴。

所以我做了一个sudo apt-get remove openjdk-9-jdk-headless,但之后java -version仍然告诉我它是 1.9。

下一次尝试是sudo apt-get remove openjdk-9-jre-headless。现在 shell 根本找不到任何 Java。到目前为止还不错,因为我故意删除了它。

现在我尝试安装 JRE 8 sudo apt-get install openjdk-8-jre-headless(我真的想知道这是否无头的是一种预兆。

我明白了

Reading package lists... Done
Building dependency tree       
Reading state information... Done
openjdk-8-jre-headless is already the newest version (8u151-b12-0ubuntu0.16.04.2).
openjdk-8-jre-headless set to manually installed.
The following packages were automatically installed and are no longer required:
  ant ant-optional aspectj default-jdk default-jdk-headless
  eclipse-platform-data eclipse-rcp fastjar gconf2 jarwrapper junit junit4
  libapache-pom-java libart-2.0-2 libasm3-java libasm4-java libaspectj-java
  libbonobo2-0 libbonobo2-common libbonoboui2-0 libbonoboui2-common
  libcanberra0 libcglib3-java libcommons-beanutils-java libcommons-cli-java
  libcommons-codec-java libcommons-collections3-java libcommons-compress-java
  libcommons-dbcp-java libcommons-digester-java libcommons-httpclient-java
  libcommons-logging-java libcommons-parent-java libcommons-pool-java
  libdb-java libdb-je-java libdb5.3-java libdb5.3-java-jni libeasymock-java
  libecj-java libequinox-osgi-java libfelix-bundlerepository-java
  libfelix-gogo-command-java libfelix-gogo-runtime-java
  libfelix-gogo-shell-java libfelix-osgi-obr-java libfelix-shell-java
  libfelix-utils-java libgail18 libgeronimo-jpa-2.0-spec-java
  libgeronimo-osgi-support-java libglade2-0 libgnome-2-0
  libgnome-keyring-common libgnome-keyring0 libgnome2-0 libgnome2-bin
  libgnome2-common libgnomecanvas2-0 libgnomecanvas2-common libgnomeui-0
  libgnomeui-common libgnomevfs2-0 libgnomevfs2-common libhamcrest-java
  libice-dev libicu4j-49-java libicu4j-java libjetty8-java libjline-java
  libjsch-java libjtidy-java libkxml2-java liblucene2-java libobjenesis-java
  liborbit-2-0 libosgi-annotation-java libosgi-compendium-java
  libosgi-core-java libosgi-foundation-ee-java libpthread-stubs0-dev
  libregexp-java libservlet3.0-java libservlet3.1-java libsm-dev
  libswt-cairo-gtk-3-jni libswt-glx-gtk-3-jni libswt-gnome-gtk-3-jni
  libswt-gtk-3-java libswt-gtk-3-jni libswt-webkit-gtk-3-jni libtdb1
  libtomcat7-java libx11-dev libx11-doc libxau-dev libxcb1-dev libxdmcp-dev
  libxt-dev openjdk-8-jdk sat4j sound-theme-freedesktop x11proto-core-dev
  x11proto-input-dev x11proto-kb-dev xorg-sgml-doctools xtrans-dev
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.

好的,我可以读写,因此我执行了建议的自动删除并重复了安装命令,但仍然没有 Java:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
openjdk-8-jre-headless is already the newest version (8u151-b12-0ubuntu0.16.04.2).
0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.

发生了什么事?我该如何解决?

答案1

您不必卸载 Java 9 即可更改版本。运行此命令以指定默认使用的 Java 版本:

$ sudo update-alternatives --config java

相关内容