1. download the latest version of JDK, I downloaded from the http://www.oracle.com/technetwork/java/javase/downloads/index.html, the network speed is really slow here. I downloaded the: Java SE Development Kit 621jdk-6u21-linux-i586.bin file.
2. Extract
Open its folder under the command line and type chmod U + X./jdk-6u21-linux-i586.bin (Change executable permissions: U indicates the owner of the file, + indicates adding permissions, X indicates executable)
Then./jdk-6u21-linux-i586.bin
Then we can see that it is decompressed. After decompression, the default directory name is jdk1.6.0 _ 21.
3. Change the Directory
Sudo CP-r jdk1.6.0 _ 21/usr/(CP-R: recursive continuous replication, used for directory replication .)
Copy it to the USR directory.
4. Set environment variables:
Call VI ~ /. Bashrc (see http://yanxi.bokewu.com/blog93673.htm for the VI command
Http://hi.baidu.com/liaoxianyi/blog/item/d6d6d854d359fe5d574e002d.html)
Enter the user environment variable configuration interface and add the following three lines to the end. ESC,: WQ
Export java_home =/usr/jdk1.6.0 _ 21
Export classpath = $ classpath: $ java_home/lib: $ java_home/JRE/lib
Export Path = $ java_home/bin: $ java_home/JRE/bin: $ path: $ homr/bin
5. Test
We can write a simple helloworld program file like the following: helloworld. Java
// File name: helloworld. Java
Public class helloworld
{
Public static void main (string [] ARGs)
{
System. Out. println ("helloworld! ");
}
}
Run the following commands in the helloworld. Java directory:
Sudo/usr/jdk1.6.0 _ 21/bin/javac helloworld. Java
Java helloworld
References:
Build a Java environment
Http://www.cnblogs.com/ghj1976/archive/2010/04/14/1711895.html