You can select the default Java Version by running the following command:
sudo update-alternatives --config java
Select the Java Installation you want to use per default by typing the selection number. Check the default Java Version by running java -version. It should print something similar to the following:
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
Answer from Samuel Philipp on askubuntu.comYou can select the default Java Version by running the following command:
sudo update-alternatives --config java
Select the Java Installation you want to use per default by typing the selection number. Check the default Java Version by running java -version. It should print something similar to the following:
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
jre-headless is okay if the java app you want to run has no gui.
sudo update-alternatives --config java
has potential inconsistent java env issue. See Setting JDK 7 as default
How to update-java-alternatives successfully to Oracle's one in Debian? - Unix & Linux Stack Exchange
On Debian 8 update-java-alternatives generate multiple errors
update-alternatives: error: no alternatives for mozilla-javaplugin.so
linux - update-alternatives: error: alternative /usr/lib/jvm/jdk1.8.0_312/bin/java for java not registered; not setting - Stack Overflow
update-java-alternatives has options to update --jre-headless, --jre, and --plugin separately.
Using
sudo update-java-alternatives --jre-headless --jre --set java-1.8.0-openjdk-amd64
worked for me on a Debian Jessie server with no plugin installed.
The easiest way to achieve this in Debian is using this command
update-alternatives --config java
Then you will get a output like this:
*0 /usr/lib/jvm/java-8-openjdk-amd64/bin/java auto mode
1 /usr/lib/jvm/jdk1.7.0/bin/java manual mode
Then you can change your default selection (marked with "*") by typing the index number. For example you select "1" in order to use Java 7 as default JVM. You can run the command again in order to check changes.
Hope it helps.
Sun-6-java is being phased out by Oracle and is no longer supported. This is why there are no plugins available for your browser anymore.
OpenJDK is the only stack you should be using as sun-java-6 is outdated and deprecated.
http://en.wikipedia.org/wiki/OpenJDK
If you would like to use Proprietary Closed Source features in Java you will need to install the version from java.com (which is also OpenJDK so don't really see any benefit over the Ubuntu Repository version).
OpenJDK is backwards compatible with the old Sun-6-java. What can you not run with OpenJDK?
Oracle Offers Links to Java 7, you have to go out of your way to get Java 6.
The previous edit to my post by "broiyan" is depricated.
Actually you can simply add the partner repository in /etc/apt/sources.list :
deb http://archive.canonical.com/ubuntu lucid partner
If you are not on lucid, replace lucid with your distribution (you can get it with lsb_release -c).
If you still have problem with the java plugin, you can do like I did, follow the instructions here :
sudo update-alternatives --install /usr/lib/mozilla/plugins/mozilla-javaplugin.so mozilla-javaplugin.so /usr/lib/jvm/java-6-sun/jre/lib/amd64/libnpjp2.so 1
If you are not on a 64 bits system, replace amd64 by i386.
if you need to install java in Ubuntu, you can try using following command and you will get oracle-java-installer in your synaptic package manager, click it and install it.
sudo add-apt-repository ppa:webupd8team/java
Else try following steps
$ wget http://download.oracle.com/otn-pub/java/jdk/6u34-b04/jre-6u34-linux-i586.bin
$ chmod u+x jre-6u34-linux-i586.bin
$ ./jre-6u34-linux-i586.bin
$ sudo mkdir -p /usr/lib/jvm
$ sudo mv jre1.6.0_34 /usr/lib/jvm/
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jre1.6.0_34/bin/java" 1
$ sudo update-alternatives --install "/usr/lib/mozilla/plugins/libjavaplugin.so" "mozilla-javaplugin.so" "/usr/lib/jvm/jre1.6.0_34/lib/i386/libnpjp2.so" 1
$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jre1.6.0_34/bin/javaws" 1
The issue is that you have created a folder named "java" in /usr/bin . Remove the folder from /usr/bin and run the command again.
The trick is to use update-java-alternatives (from the java-common package).
So to go for OpenJDK 6 to 7, I used update-java-alternatives -l to get a list of Java alternatives and then used sudo update-java-alternatives -s java-1.7.0-openjdk-amd64 to the JDK.
NOTE: The command above threw the following errors,
update-alternatives: error: no alternatives for mozilla-javaplugin.so.
update-java-alternatives: plugin alternative does not exist: /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/IcedTeaPlugin.so
This is because the openjdk plugin is not installed by default. To fix run
sudo apt-get install icedtea-7-plugin
and rerun update-java-alternatives.
< TL;DR > update-java-alternatives uses the .jinfo file to determine which alternatives to switch across but also expects them to have been configured separately.
Create a new .jinfo file and update-alterntive entries if your downloaded JRE/JDK does not switch over with update-java-alternatives
[Details]
To configure it manually:
Decompress your new jdk alongside the existing jdk in
/usr/lib/jvm/Generate a .jdkname.jinfo file by duplicating another .jinfo file in the folder (or grab one from another Ubuntu install: you are after the template as much as anything else).
The filename .jdkname.jinfo must match the jdk foldername.
Modify the content to set the header (names) and the file paths (program entries) to match your new install.
Remove any lines referring to programs omitted in your version and add lines for new programs in
/binGenerate alternatives for all the programs now in your .jinfo package with this template:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/**jdkname**/bin/java 100(Several related answers have scripted this from the contents of /bin or you can perform regexp search/replace on your .jinfo file to generate the script commands.)
Note the 100 is just the priority which is considered when setting the jdk version using the auto flag.
Check the java alternatives and switch to use the JDK.
update-java-alternatives -l update-java-alternatives -s jdknameNote that some JDKs do not include the JRE, so either add it or remove those jinfo entries.