3

How to set default Java version on Ubuntu / Debian

 3 years ago
source link: https://computingforgeeks.com/how-to-set-default-java-version-on-ubuntu-debian/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
How to set default Java version on Ubuntu
Search

In this guide, I’ll show you how you can set the default Java version on Ubuntu / Debian. It is common to run more than one version of Java in your Ubuntu or Debian system – For development reasons or varying applications requirements.

set default java ubuntu debian

Earlier on we had done an article on installing Java 11 on Ubuntu / Debian: How to Install Java 11 on Ubuntu 18.04 /16.04 / Debian 9

For Java 8: How to Install Java 8 on Ubuntu

Suppose you install Java 11 and you had another version of Java installed earlier, you can select default Java version to use using the update-alternatives --config java command.

Checking Java versions installed on Ubuntu / Debian

To get a list of installed Java versions, run the command:

$ update-java-alternatives --list
java-1.11.0-openjdk-amd64 1101 /usr/lib/jvm/java-1.11.0-openjdk-amd64
java-8-oracle 1081 /usr/lib/jvm/java-8-oracle

Once you have a list of Java version, set a default one by running the command:

$ 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   1101      auto mode
* 1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1101      manual mode
  2            /usr/lib/jvm/java-8-oracle/jre/bin/java       1081      manual mode

Press <enter> to keep the current choice[*], or type selection number: 2

Check Java version

$ java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

The same can be done for javac.

~$ sudo  update-alternatives --config javac

There is 1 choice for the alternative javac (providing /usr/bin/javac).

  Selection    Path                                  Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-8-oracle/bin/javac   1081      auto mode
* 1            /usr/lib/jvm/java-8-oracle/bin/javac   1081      manual mode

Press <enter> to keep the current choice[*], or type selection number: 

If JAVA_HOME is not set correctly, run the command below to set from current default Java configured.

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")

For JRE, use:

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:jre/bin/java::")

Persistence can be achieved by placing the export command in your .bashrcor/etc/profilefile.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK