I.Download JDK
1. log on to the Sun JDK official download URL: http://java.sun.com/javase/downloads/index.jsp
2. Download The jdk-1_5_0_07-linux-i586-rpm.bin File
Ii. Install JDK
1. Add executable permissions for jdk-1_5_0_07-linux-i586-rpm.bin files
# Root> chmod 755 jdk-1_5_0_07-linux-i586-rpm.bin
2. Perform jdk-1_5_0_07-linux-i586-rpm.bin
# Root>./jdk-1_5_0_07-linux-i586-rpm.bin
3. Install the PrM package file
# Root> rpm-IVH jdk-1_5_0_07-linux-i586.rpm
3. Configure the environment variables path, java_home, classpath, and jre_home.
Three environment variables are configured:
1. Modify the/etc/profile file (the system is valid)
(1) # root> VI/etc/profile
(2) Use the VI editor to add the following content before the profile file umask022 (behind done and before unset I:
Export java_home =/opt/jdk1.5 // JDK installation path
Export Path = $ java_home/bin: $ path
Export classpath =.: $ java_home/lib/dt. jar: $ java_home/lib/tools. Jar
Export jre_home = $ java_home/JRE
Make environment variables take effect: # source/etc/profile
Save and restart your computer
(3) log on again
[Note]
<1> use environment variables in Linux: separate paths, different from those in windows;
<2> in Linux, use ($ + environment variable name) to reference the original variable value. In Windows, use % + environment variable name + %. For example, $ path and % PATH %.
<3> no space exists in classpath. For example, c: \ Documents and Settings \ Seagar \ jdk1.5 in windows will be invalid path names.
<4> the current directory "." In classpath cannot be ignored.
<5> export exports environment variables as global variables
<6> case sensitivity
2. Modify the. bashrc file (valid for individual users)
(1) # root> VI/home/Seagar/. bashrc
(2) Use the VI editor to add the following statements to the. bashrc file:
Export java_home =/opt/jdk1.5 # JDK installation path
Export Path = $ java_home/bin: $ path
Export classpath =.: $ java_home/lib/dt. jar: java_home/lib/tools. Jar
Export jre_home = $ java_home/JRE
3. Modify it directly in Shell (the current shell is valid)
Export java_home =/opt/jdk1.5
Export Path = $ java_home/bin: $ path
Export classpath =. $ java_home/lib/dt. jar: java_home/lib/tools. Jar
4. Same as above
To enable JDK to be used by all users, you can:
VI/etc/profile. d/Java. Sh
Enter the following content in the new java. Sh file:
# Set Java environment
Java_home =/opt/jdk1.5
Classpath =.: $ java_home/lib/tools. Jar
Path = $ java_home/bin: $ path
Export java_home classpath path
Save and exit, and then assign the permission to Java. sh: chmod 755/etc/profile. d/Java. Sh
Run the echo command on the terminal to check the environment variable settings.
# Echo $ java_home
# Echo $ classpath
# Echo $ path
Iv. test installation
1. view the Java-version
2. Use the VI editor to compile a Java program
(1) # root> VI hello. Java
(2) Programming
Public class hello
{
Public static void main (string [] ARGs)
{
System. Out. println ("hello ");
}
}
3. Run the CD command to enter the hello. Java directory and enter javac hello. java.
4. Execute: Java hello
5. Output: Hello
5. Uninstall JDK
1. Uninstall the rpm jdk:
# Rpm-Qa | grep JDK
Show: jdk-1.6.0_10-fcs
This indicates that you have installed JDK and uninstalled it below,
Uninstall: # rpm-e -- nodeps jdk-1.6.0_22-fcs
2. Uninstall the built-in JDK version:
View the built-in JDK:
# Rpm-Qa | grep gcj
The following information is displayed:
Libgcj-4.1.2-44.el5
Java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Run the rpm-e -- nodeps command to delete the content found above:
# Rpm-e-nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115