How to install Java on Ubuntu 18.04 Bionic Beaver Linux -

Let's start by adding a PPA repository:

Namely they are java8 and java9.

To install Java 8 execute:

This is a companion discussion topic for the original entry at

Sławek J

require using command (when install java manual):

sudo update-alternatives --config java
sudo update-alternatives --config javac

My installation required a single hyphen for the java options for the verification step

$ java -version

I have tried the various methods to install jre and jdk on Ubuntu 18, but no luck. it must be missing a file or have a file in a folder that can’t be found. I am getting a runtime error on a jar file compiled from a java program. The same exact setup of java program, on Ubuntu, jre and jdk worked on other computers, so something has changed in the version of java. I get this runtime error:
Couldn’t get Method ID from voltageRationInput_classException in thread “main” java.lang.NoSuchMethodError:
at java.lang.ClassLoader$NativeLibrary.load(Native Method)

someone suggested the jre and jdk for java, javac don’t match but that is not true. I keep uninstalling and reinstalling different methods with no luck. I suppose I could go back and find older version tar files if necessary.

Anyone have ideas of how to fix this?

Hi Zman,

Welcome to our forums.

The issue you describe seem to be tricky:

This states that 1.) the same exact setup worked 2.) something changed in the java version - but this means it isn’t the same exact setup, right…?

Please post the output of:

java -version

And if you have access to a working setup, the same information would be useful from that machine. If this command provides an error, the whole Java setup is a mess; otherwise, it may be compatibility issue.

I will get to the machines and post.
java and javac version on the new machine, not working, is 1.8.0_191, as in
openjdk version “1.8.0_191”
whereas I know on the previous two machines working that it is an earlier version. Those machines were set up about 2 months ago, so maybe Oracle added new versions or else I used an archive tar file for jdk-8. I don’t think the issue is the later version but possibly where the installation is placing library files.

I fired up my most previously installed machine that is working.
The versions for java and javac are:
java version"1.8.0_191"
javac 1.8.0_191

so these are not “openjdk” but the same version number
I have tried to uninstall headless etc; not sure which version is maybe from the Oracle website or what folder options I might have set up to make the first machine work whereas the second one does not.
Both are AMD64 bit
Instead of reinstalling the LAMP stack and java again, in the hopes of downloading the right files, I thought it would be worthwhile to understand what is happening and fix it with knowledge.

I’ve tried uninstalling and reinstalling by
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
which gives me the same version numbers but still doesn’t work.
Next I download the tar files from the oracle website, for jre and jdk -8
The trick is that on the website it states for installation on Linux 64 bit:
Change directory to the location where you would like the JDK to be installed, then move the .tar.gz archive binary to the current directory. However, nowhere is there any documentation or guidance as to what directory or folder this should be installed! Just unpacking the tar file in /Downloads, I see the same exact files that I already have in
/usr/lib/jvm/java-8-roracle/jre/lib as example
so that does not seem to be the issue. But if there was direction as to where to unpack it then I could redo that to see if it makes any difference

Hi Zman,

You can extract the tar.gz anywhere on the filesystem (but there are places where you shouldn’t, like /tmp or under /home for example). A common place for such binaries is /opt.

From your previous post it seems you’ll need Oracle’s java (as I have no doubt you concluded too), and with extracting the tar.gz you already have the binaries, you only need to set the system to use them.

That’s where update-alternatives utility comes in. Executing

sudo update-alternatives --config java

Should show a list of Java environments available on your system, with the one you use currently marked with an asterisk.

Thanks. I’ve used the update-alternatives when I had several versions on the system to try among the various versions, but that did not help. So it’s still not clear what file or folder is missing. I don’t see any documentation on the specific error except for a couple of people who say their java and javac versions did not match.

Hi Zman,

What does your
sudo update-alternatives --config java
sudo update-alternatives --config javac

Outputs say at the moment?

I’ve been trying to reinstall versions without luck. The output of the current commands:
for java:
Selection Path Priority Status
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 manual mode
2 /usr/local/java/jdk1.8.0_191/bin/java 1 manual mode

for javac:
Selection Path Priority Status
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1101 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1101 manual mode
2 /usr/local/java/jdk1.8.0_191/bin/javac 1 manual mode

I might give up on this, reinstall everything with earlier versions.