Difference between revisions of "Default Java on Mint Linux"

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search
m
m (OpenJDK (example))
 
Line 81: Line 81:
 
remove
 
remove
 
  sudo apt remove openjdk-11-jdk
 
  sudo apt remove openjdk-11-jdk
 +
 +
Minecraft works with openjdk-8-jdk
 +
sudo apt install openjdk-8-jdk
 +
 
=== Oracle Java (example) ===
 
=== Oracle Java (example) ===
  

Latest revision as of 19:28, 9 November 2022

or how to configure the default Java on Linux Mint when more than one version is installed. I am fairly certain that this applies to most of the Debian derivatives such as those considered spin-offs of Ubuntu.

Also, below explains how to get rid of ugly IBM Java old crappy version also known as IBM Java Runtime Environment.

Ubuntu / Mint needs some kind of Java for software like LibreOffice to function. In the absence of Oracle or OpenJDK it will, without asking you, install ibm-java80-jre which is compatible with very little today. Get rid of it...

sudo apt remove ibm-java80-jre

The Ubuntu / Mint insists on having either OpenJDK or IBM Java on the system. Even if you install Oracle Java (real Java) you will still have one of the others unless you really go in and start ripping things out manually, which can be a bad thing.

Got lots of Java binaries floating around? Java bin here and there, multiple versions, finding out that OpenJDK version 11 hates Minecraft or other games?

You can have more than one version on the system. You can configure your software to pick a specific version. However, the system references a default Java binary in the absence of a specific path and sometimes dependencies of the Java application will, even when launched specifically from the command line, refer to the default configured system.

 /usr/bin/java -jar somesoftware.jar

YOU CAN USE A SYSTEM COMMAND TO SET THE DEFAULT JAVA PREFERENCE

update-alternatives --config java

You will see something like this:

here are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      auto mode
* 1            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode

The minecraft launcher is not popular with OpenJDK 11 however works well with OpenJDK 8.

Now that we changed our default, lets run the java command without absolute path to the java

# java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~18.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

Looks good! It is no longer reporting version 11.

What the update-alternatives script does is maintains symbolic links to various executable binaries in directories like /usr/bin because those are the ones executed by default from the environment path. The command isn't just for picking a Java version.

Troubleshooting

Error: There is only one alternative in link group java

  1. Download the version you wish to run, for our example Oracle 8 from the file jre-8u181-linux-x64.tar.gz
  2. Extract jre-8u181-linux-x64.tar.gz to /usr/local (or what is appropriate for your distribution, see below) - you end up with the java binary in the path: /usr/local/jre1.8.0_181/bin
  3. Add the java to the update-alternatives link group - sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/jre1.8.0_181/bin/java" 8
  4. Then run update-alternatives

Linux Mint 19.2 - Extract jre-8u181-linux-x64.tar.gz to /usr/lib/jvm - you end up with the java binary in the path: /usr/lib/jvm/jre1.8.0_181/bin

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jre1.8.0_181/bin/java" 8

You will have to fix file permissions to match the other stuff in that directory. chown root, chgrp root, chmod 755 recursive within the jre1.8.0_181 folder.

To test, remember only one dash - on the version "java -version" command line switch

/usr/lib/jvm/jre1.8.0_181/bin/java -version

Here is the Linux Mint 19.2 Example:

$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jre1.8.0_181/bin/java" 8
$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                         Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1111      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1111      manual mode
  2            /usr/lib/jvm/jre1.8.0_181/bin/java            8         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/jre1.8.0_181/bin/java to provide /usr/bin/java (java) in manual mode
$ java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

Cinnamon desktop shell menu says to open with one version yet it opens in another

For example you right click on a jar file and choose to open with Oracle Java 8 yet it opens in OpenJDK 8.

On versions of Linux Mint / Cinnamon the Java Alternatives version you choose will override what the shell menu displays. The shell does not know what mapping is in the sub system. You can always set a specific path in the shell or just drop to CLI and change the alternative you wish to use for the particular jar file. Hard setting the path in the shell is probably possible too.

Howto Install ...

OpenJDK (example)

install

sudo apt install openjdk-11-jdk

remove

sudo apt remove openjdk-11-jdk

Minecraft works with openjdk-8-jdk

sudo apt install openjdk-8-jdk

Oracle Java (example)

Crappy IBM Java (example)

install

sudo apt install ibm-java80-jre

remove

sudo apt remove ibm-java80-jre

See: IBM Java Runtime Environment

Some Related Pages