For java 6, download bin file from oracle archive
Create a folder:
$ sudo mkdir -p /opt/java
Move bin file to that folder. Then:
$ sudo chmod +x jdk-6u45-linux-x64.bin
$ sudo ./jdk-6u45-linux-x64.bin
Now, you have to use update-alternatives
to install java
$ sudo update-alternatives --install /usr/bin/java java /opt/java/jdk1.6.0_45/bin/java 0
$ sudo update-alternatives --install /usr/bin/javac javac /opt/java/jdk1.6.0_45/bin/javac 0
Donwload the java 7 file from the Oracle Archive and place it into de /opt/java
folder.
This is a tar file, so, we have to untar manually:
$ sudo tar zxvf jdk-7u80-linux-x64.tar.gz
Finally, we have to do the same with update-alternatives
:
$ sudo update-alternatives --install /usr/bin/java java /opt/java/jdk1.7.0_80/bin/java 0
$ sudo update-alternatives --install /usr/bin/javac javac /opt/java/jdk1.7.0_80/bin/javac 0
Donwload the java 8 file from the Oracle Archive and place it into de /opt/java
folder.
This is a tar file, so, we have to untar manually:
$ sudo tar zxvf jdk-8u241-linux-x64.tar.gz
Finally, we have to do the same with update-alternatives
:
$ sudo update-alternatives --install /usr/bin/java java /opt/java/jdk1.8.0_241/bin/java 0
$ sudo update-alternatives --install /usr/bin/javac javac /opt/java/jdk1.8.0_241/bin/javac 0
Using update-alternatives
we can choose the installation that is in use:
$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /opt/java/jdk1.6.0_45/bin/java 0 auto mode
1 /opt/java/jdk1.6.0_45/bin/java 0 manual mode
2 /opt/java/jdk1.7.0_80/bin/java 0 manual mode
3 /opt/java/jdk1.8.0_241/bin/java 0 manual mode
Press <enter> to keep the current choice[*], or type selection number:
You choose the selection typing the number. Then you can test it:
$ java -version
java version "1.8.0_241"
Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)
$ sudo update-alternatives --remove java /path/to/java
$ sudo update-alternatives --remove javac /path/to/javac
Enjoy!