[last updated: 2019-05-23]
go to: Java
-----
This page is a record of everything I did, including what didn't work.
If you want the short version that worked, go here:
(go to:) Successful Java Install on Linux
Everything below here is just a record of things that didn't work and can be ignored.
[FORMATTING ON THIS PAGE IS NOT CLEANED...]
-----
-----
- link to: wikiHow
- This method did not work and was abandoned...
- under Method 1: Installing on Non-RPM Linux,
click "Java for Linux Download page"
link to: download Java for Linux
- At the bottom of the colored box, click: jdk.java.net
- At "Ready for Use" click "JDK 12"
This will download the Openjdk release
- At JDK 12.0.1 General Availability Release page
under Builds - Linux/x64, click tar.gz
select "Open with ..." Archive Manager (default), click OK
wait ...
- Dialogue box opens, with filename at top, labeled [read only]
At this point, instructions in the wikiHow diverge from what I'm seeing.
Instructions say I should have a filename of the form "jre-8uxxx"
but my filename is jdk...
Best guess at this point is that these instructions are written for full version,
while I'm attempting to install the free OpenJDK version.
- Abandoning this path
- link to: Instructions for downloading and installing JRE - Java Runtime Environment"
JDK is a superset of JRE, and contains everything that JRE contains, plus other stuff.
Bottom line, since I'm installing JDK, I don't need JRE.
- Another attempt:
- Since java will be installed in usr/java, and there was no such directory, I created one with $sudo mkdir.
- Downloaded the openjdk...tar.gz into Downloads folder.
- Used sudo mv to move it into the usr/java folder.
- link to: these instructions
say to unpack the .gz with this:
$ tar xvf openjdk-12*_bin.tar.gz
- Amazing - it seems to have worked. Everything was extracted into a new folder: jdk-12.0.1
- $ java -version returns:
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.16.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
- This tutorial for Beginners from guru99
Great installation notes, as well as instructions for actually using Java:
- Specifically:
After successful installation, as evidenced by $ java -version,
use text editor to write a Java program, save as [filename].java
Then compile it ...
But first, must set System variables in profile.
- $ sudo nano /etc/profile
- add these lines to the end of the file:
JAVA_HOME=/usr/java/jdk-12.0.1
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH
ctrl-o to write/save, then press enter
ctrl-x to exit
- $ . /etc/profile to reload profile
- ... now compile it with $ javac [filename].java
This creates a file named as the name of the class that you've defined in your program, and has a .class extension
- Then this file is executed with $ java [fileClassName]
- However when I did this, I got an error...
- Actual error (key things at least...):
JNI error has occurred
UnsupportedClassVersionError
"A" (name of my compiled file, = name of the class that was defined in ... .java)
has been compiled by a more recent version of JRE
"A" was compiled with version 56.0, but this version of JRE only recognizes class file versions up to 52.0
...
- ...now searching forums and hacking through to a solution...
- maybe try uninstalling Java 12.0 and instead install 8?
- This forum note says:
Java SE 12 = 56
Java SE 8 = 52
and further suggests "either run the Java code with a newer version of Java JRE, or specify the target parameter to the Java compiler to instruct the compiler to create code compatible with earlier Java versions." with code snippet offered...
- Another attempt:
- Did apt-get update & dist-upgrade
- $ dpkgs --list
does not show JDK12 (however I forgot to look in the very long list for openjdk...)
Best guess is that the back-door method I used to install it (downloading the tar and unpacking)
was not best/proper way to install it
- Intention is to uninstall JDK 12, and install JDK 8 instead.
However as above, JDK 12 is not listed with dpkg command,
so I can't use apt-get to uninstall,
so I will uninstall the same way I installed it,
manually deleting the files I copied in,
as well as the usr/java directory I created
- Then to install:
$ sudo apt-get install openjdk-8-jdk
- It seemed to work, however it did not re-create the usr/java directory...
OTOH openjdk is listed in dpkg list
- I discovered that, since I was in the /etc directory when I did the apt-get install,
that's where it put the java-8-openjdk directory.
OTOH that's not where I want it, so I manually moved it
to the /usr/java directory that I created
- Amazingly, it all worked. Test Java with 'Hello World'
- ...
eof