This article is reproduced in http://my.oschina.net/boltwu/blog/403555
1. Download the JDK
The Linux operating system is: centos6.5-x64
Currently the latest JDK version is: Java SE development Kit 7u80
: http://download.oracle.com/otn-pub/java/jdk/7u80-b15/jdk-7u80-linux-x64.tar.gz
Check Latest: http://www.oracle.com/technetwork/java/javase/downloads/index.html
All versions Archive: http://www.oracle.com/technetwork/java/javase/archive-139210.html
2. Unzip the installation
We install the JDK to this path:/usr/local/java
If there is no such directory (the first time of course not), we will create a new directory
?
| 12 |
cd/usr/localsudo mkdirjava |
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
?
| 123 |
sudotar zxvf ./jdk-7u80-linux-x64.tar.gz -C /usr/local/javacd /usr/local/javasudo mvjdk1.7.0_80 jdk1.7.0 |
3. Configure environment variables?
Add at the end of the open file
?
| 12345 |
# export Java env export java_home= /usr/local/java/jdk1 .7.0 export jre_home= /usr/local/java/jdk1 .7.0 /jre export classpath=.:%java_home% /lib/dt .jar:%java_home% /lib/tools .jar export path= $JAVA _home /bin : $JRE _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:
?
| 12345 |
sudo update-alternatives --install /usr/bin/java java /usr/local/java/jdk1.7.0/bin/java 300sudo update-alternatives --install /usr/bin/javac javac /usr/local/java/jdk1.7.0/bin/javac 300sudo update-alternatives --install /usr/bin/jar jar /usr/local/java/jdk1.7.0/bin/jar 300sudo update-alternatives --install /usr/bin/jcontrol jcontrol /usr/local/java/jdk1.7.0/bin/jcontrol 300sudo update-alternatives --install /usr/bin/jps jps /usr/local/java/jdk1.7.0/bin/jps 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.
You can also delete the path configuration using the Update-alternatives--remove command, as follows:
?
| 1 |
sudoupdate-alternatives --remove javac /usr/local/java/jdk1.7.0/bin/javac |
Execute the following code to see the current various JDK versions and configurations:
?
| 1 |
sudoupdate-alternatives --config java |
Open a terminal and enter the following command:
5. Test?
Show Results:
?
| 123 |
java version "1.7.0_80"Java(TM) SE Runtime Environment (build 1.7.0_80-b15)Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode) |
This means that the Java command is ready to run.
Linux installation Java