On Ubuntu, you can either choose the default OpenJdk or install the Oracle JDK through a additional software repository. The latter method is preferred. Starting with Ubuntu 14.04 both methods allow to install different JDK versions and let them co-exists on your system.
-
Option 1: OpenJdk (maintained by canonical)
OpenJdk versions 7 and 8 can be installed through the official repos starting Ubuntu trusty.
$ sudo apt-get install openjdk-8-jdk
To set the system wide default jdk, simply launch the
update-alternatives
command :$ sudo update-alternatives --config java
-
Option 2: Oracle JDK (preferred - most compatible)
The Oracle JDK is available through an external repo.
$ sudo apt-get install python-software-properties $ sudo add-apt-repository ppa:webupd8team/java $ sudo apt-get update $ sudo apt-get install oracle-java8-installer
To set the system wide default jdk, simply install the
oracle-javaX-set-default
package, where X stands for the version you need.$ sudo apt-get install oracle-java8-set-default
On redhat systems,