1. Install java 8

	$ sudo add-apt-repository ppa:webupd8team/java
	$ sudo apt-get update
	$ sudo apt-get install oracle-java8-installer
	

2. Verify the java version by using the following command

	$ java -version
	

3. You can set the default version by using the below command

	sudo apt-get install oracle-java8-set-default
	

4. Changing the java version when there are multiple versions.
4.1 Check the avilable java versions

	$ sudo update-alternatives --display java

	namal@namal:~$ sudo update-alternatives --display java
	[sudo] password for namal: 
	java - auto mode
	  link currently points to /usr/lib/jvm/java-8-oracle/jre/bin/java
	/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java - priority 1071
	  slave java.1.gz: /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz
	/usr/lib/jvm/java-8-oracle/jre/bin/java - priority 1072
	  slave java.1.gz: /usr/lib/jvm/java-8-oracle/man/man1/java.1.gz
	Current 'best' version is '/usr/lib/jvm/java-8-oracle/jre/bin/java'.
	

4.2 Config to use another java version

	$ sudo update-alternatives --config java

	namal@namal:~$ 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-8-oracle/jre/bin/java          1072      auto mode
	  1            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
	  2            /usr/lib/jvm/java-8-oracle/jre/bin/java          1072      manual mode

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

4.3 Double check the java version

	$ java -version

	namal@namal:~$ java -version
	java version "1.8.0_91"
	Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
	Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
	

5. Change the java version using by the IDE ( eg: eclipse)
-vm
/usr/lib/jvm/java-8-oracle/jre/bin
-vmargs
-Dosgi.requiredJavaVersion=1.8

 

References 

 

Advertisements