1. Download the JDK
Currently the latest JDK version is: Java SE development Kit 8u51
: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
2. Unzip the installation
We install the JDK to this path:/USR/LIB/JVM, and modify the name to facilitate management
sudo mkdir /usr/lib/jvm
sudo tar vxf jdk-8u51-linux-x64.tar.gz -C /usr/lib/jvm/cd /usr/lib/jvmsudo mv jdk1.8.0_51 jdk8
3. Configure Environment variables
gedit ~/.bashrc
Add at the end of the open file
# java jdk 1u8
export JAVA_HOME=/usr/lib/jvm/jdk8export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/libexport PATH=${JAVA_HOME}/bin:$PATH
Save the exit and enter the following command to make it effective
source ~/.bashrc
4. Configure the default JDK
Some Linux distributions already have default JDK, such as OPENJDK. So in order to make the JDK version we just installed can be the default JDK version, we will also make the following configuration.
Execute the following command:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk8/bin/java 300sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk8/bin/javac 300
Note: If the above two commands do not find a path problem, just restart the computer and repeat the above two lines of code is OK.
Execute the following code to see the current various JDK versions and configurations:
sudo update-alternatives --config java
5. Testing
Open a terminal and enter the following command:
java -version
Show Results:
java version "1.7.0_05"Java(TM) SE Runtime Environment (build 1.7.0_05-b05)Java HotSpot(TM) Server VM (build 23.1-b03, mixed mode)
This means that the Java command is ready to run.
ubuntu14.04 Configuring the Java JDK