網頁

2014年4月27日 星期日

Ubuntu 14.04 --- Install Oracle Java 7 & 8 via PPA and set the environment variable

Due to some application require Oracle Java, we have to install it in the Ubuntu Desktop 14.04 LTS x64 besides OpenJDK.ScreenHunter_104
How to install Oracle Java?
At first, we have to add an PPA by using the sudo add-apt-repository ppa:webupd8team/java for installing the latest Oracle Java as Java7 or Java8 in Ubuntu.
ScreenHunter_101
To update package list again by using sudo apt-get update commandScreenHunter_102
If we want to install Oracle Java7, we can execute the sudo apt-get install oracle-java7-installer command. (# 1)ScreenHunter_105Of course, if we want to install Oracle Java8, we can execute the sudo apt-get install oracle-java8-installer command.

When the installation finish and success, we can realize which version will be used later by using the java -version commandScreenHunter_109
As you know, if there is more than one version of Java,we have to choose one Java version to use in the system.
How to do it?
By using the sudo update-alternatives --config java command next to select one version as the following choice for us. (# 2)ScreenHunter_110So do that we also can understand the path of the java installation. If we have this information,we can set the “JAVA_HOME”  and “JRE_HOME” environment variable later.
How to do it? At first, we need to know what is value on the “JAVA_HOME” variable by using the echo $JAVA_HOME command or “JRE_HOME” variable by using the echo $JRE_HOME commandScreenHunter_112 As the above result, there is no any setting in this system now.

In the moment, we have already changed the default java to Java8 so that the java full path is /usr/lib/jvm/java-8-oracle/jre/bin/java
As to the environment variable setting, we have two method to do it.
For every user, we can set the environment variable by editing the /etc/profile fileScreenHunter_121
For a particular user, we can set the environment variable by adding something in the end of the /home/<users>/.bashrc fileScreenHunter_122
To reload this file and test it by using the echo $JAVA_HOME or echo $JRE_HOME command again
It will return the set path so that the environment variable has been set successfully.ScreenHunter_119Until now, we have already finished the Oracle JAVA installation and the environment variable setup.

Reference :
(# 1)   Due to the WebUpd8 Oracle Java PPA doesn’t include any java binary files, it will help us to download and install Oracle Java automatically. In the installation process, we have to accept the license agreement as follows to go ahead.ScreenHunter_107(# 2)   As to change the Java compiler(javac), it has a little different that just replace java with javac word as the sudo update-alternatives --config javac command.

沒有留言:

張貼留言

Since 2010 Design by Davidwa
©Copyright Davidwa Inc. All rights reserved.