3

Background of the question is that I have tried (in vain) to set up my newly installed box with Java 9 together with Eclipse Oxygen.

Those won't work together (there are multiple questions about this, and it looks like every problem is a special case with a different cause).

The direct reason seams to be that Eclipse (eclipse.ini) cannot start the JVM, and the popup with the parameters is not even accessible to copy & paste.

So I did a sudo apt-get remove openjdk-9-jdk-headless, but after that java -version still told me it's 1.9.

Next try was sudo apt-get remove openjdk-9-jre-headless. Now the shell can't find any Java at all. Fine, so far, as I deliberately removed it.

Now I tried to install JRE 8 with sudo apt-get install openjdk-8-jre-headless (and I really wonder if that headless is kind of an omen).

I get

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.

OK, I can read and write, so I did that proposed autoremove and repeated the install command, but still have no 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.

What is happening, and how can I fix it?

Chai T. Rex
  • 5,193
  • Your output isn't easy to read (interpret the errors). It appears you clicked on the quote markup rather than the code markup. The code markup will preserve the formatting which is easier for to interpret. Consider re-running your commands and editing your question and replacing the current quoted text with coded markup. If you advise me when it's done, it would be a breeze for me to glance at it and identify what's going wrong. – L. D. James Jan 11 '18 at 00:25
  • @L.D.James right you are, I didn't notice. – Gyro Gearloose Jan 11 '18 at 00:41
  • For most java-dependent applications, I will set their java path explicitly in the application's configuration files. Often this is through the JAVA_HOME environment variable -- or something similar -- to the package I get from Oracle. This gets around some of the issues that arise when using a global java path, and also gives flexibility where one application wants version x and another wants version y I'm sure there are excellent reasons against this approach but I haven't encountered any in the fifteen+ years I've been using java. – Stephen Boston Jan 11 '18 at 02:22

1 Answers1

12

You didn't have to uninstall Java 9 to change versions. Run this to specify the java version to be used by default:

$ sudo update-alternatives --config java
L. D. James
  • 25,036
  • Thank you, but doesn't work: update-alternatives: warning: alternative /usr/lib/jvm/java-9-openjdk-amd64/bin/java (part of link group java) doesn't exist; removing from list of alternatives

    update-alternatives: warning: /etc/alternatives/java is dangling; it will be updated with best choice

    There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-9-openjdk-amd64/bin/java Nothing to configure.

    – Gyro Gearloose Jan 11 '18 at 00:58
  • The new error you're seeing may be related to incomplete installations (resulting from your previous attempt to remove version 9). I suggest that you satisfy the update-alternatives app to have a choice by reinstalling version 9. Run sudo apt install openjdk-9-jdk openjdk-8-jdk. Then use the update-alternatives app. – L. D. James Jan 11 '18 at 01:06
  • It quite looks like I have messed up my system: Errors were encountered while processing: /var/cache/apt/archives/openjdk-9-jdk_9~b114-0ubuntu1_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1) – Gyro Gearloose Jan 11 '18 at 01:10
  • It looks like ubuntu lost track of installed packages. I have quite a talent for doing havoc on software ;-) . – Gyro Gearloose Jan 11 '18 at 01:14
  • Run this: sudo dpkg -i --force-overwrite /var/cache/apt/archives/openjdk-9-jdk_9~b114-0ubuntu1_amd64.deb – L. D. James Jan 11 '18 at 01:18
  • dpkg: error processing archive /var/cache/apt/archives/openjdk-9-jdk_9~b114-0ubuntu1_amd64. (--install): cannot access archive: No such file or directory dpkg: error processing archive deb (--install): cannot access archive: No such file or directory Errors were encountered while processing: /var/cache/apt/archives/openjdk-9-jdk_9~b114-0ubuntu1_amd64. deb --- looks like I have really wrecked the system. Is there some kind of reset? The box is freshly installed, so redoing the install would not be too catastrophic. – Gyro Gearloose Jan 11 '18 at 01:21
  • Does the update-alternative app still give errors? If so there are two other commands that may satisfy it. As far as the fresh install, if you decide to do that instead of addressing the issue, I understand. But I assure you, you will likely have lots of such issues from time to time. Becoming familiar with how to address it now may be a good time. Starting over so quickly might prove in a long time to be substantially more timely, when it comes to trying to get your system configured ideally to your liken. – L. D. James Jan 11 '18 at 01:26
  • Um, I didn't down-vote, but I'll wait with further tries until the experts have settled the cause. – Gyro Gearloose Jan 11 '18 at 01:29