Original address: http://blog.sina.com.cn/s/blog_93dc666c0101b1bj.html1. Download JDK
Currently the latest JDK version is: Java SE development Kit 7u5
: http://download.oracle.com/otn-pub/java/jdk/7u5-b06/jdk-7u5-linux-i586.tar.gz
Check Latest: http://www.oracle.com/technetwork/java/javase/downloads/index.html
2. Unzip the installation
We install the JDK to this path:/USR/LIB/JVM
If there is no such directory (the first time of course not), we will create a new directory
| 1 2 |
Cd/usr/lib sudo mkdirjvm |
After the establishment of the good, we came to the download of the compressed package directory, extracted to our newly created folder inside, and modify the name to facilitate our management
| 1 2 3 |
sudo tar zxvf./jdk-7-linux-i586.tar.gz-c/USR/LIB/JVM CD/USR/LIB/JVM sudo mvjdk1.7.0_05./jdk7 |
3. Configure Environment variables
Add at the end of the open file
| 1 2 3 4 |
Exportjava_home=/usr/lib/jvm/jdk7 Exportjre_home=${java_home}/jre Exportclasspath=.:${java_home}/lib:${jre_home}/lib Exportpath=${java_home}/bin: $PATH |
Save the exit and enter the following command to make it effective
4. Configure the default JDK (this step can be omitted in general)
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:
| 1 2 |
sudo update-alternatives--install/usr/bin/java java/usr/lib/jvm/jdk7/bin/java sudo update-alternatives--install/usr/bin/javac javac/usr/lib/jvm/jdk7/bin/javac |
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:
| 1 |
Sudoupdate-alternatives--config Java |
5. Testing
Open a terminal and enter the following command:
Show Results:
| 1 2 3 |
java Version "1.7.0_05" Java (TM) SE Runtime Environment (BUILD1.7.0_05-B05) Javahotspot (TM) Server VM (build23.1-b03,mixed mode) |
This means that the Java command is ready to run.