Unzip and install jdk
Enter the directory where the jdk-6u14-linux-i586.bin file is located under the shell terminal, and execute the command ./jdk-6u14-linux-i586.bin. At this time, an agreement will appear, continue to press Enter, when asked whether you agree , enter yes, and press Enter. After that, a jdk1.6.0_14 directory will be generated in the current directory, and you can copy it to any directory.Environment variables that need to be configured
1. PATH environment variable. The function is to specify the command search path. When the command is executed under the shell, it will look in the path specified by the PATH variable to see if it can find the corresponding command program. We need to add the bin directory under the jdk installation directory to the existing PATH variable. The bin directory contains frequently used executable files such as javac/java/javadoc. Execute tools such as javac/java.2. CLASSPATH environment variable. The role is to specify the class search path. To use the classes that have been written, of course, the premise is that they can be found. The JVM searches for classes through CLASSPTH. We need to set dt.jar and tools.jar in the lib subdirectory under the jdk installation directory to CLASSPATH. Of course, the current directory "." must also be added to this variable.
3. JAVA_HOME environment variable. It points to the jdk installation directory, and software such as Eclipse/NetBeans/Tomcat finds and uses the installed jdk by searching the JAVA_HOME variable.
Three ways to configure environment variables
1. Modify the /etc/profile file
This method is recommended if your computer is only used for development, since all users' shells have access to these environment variables, which may cause security problems for the system.·Open /etc/profile with a text editor
·Add at the end of the profile file:
export JAVA_HOME=/usr/share/jdk1.6.0_14
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt .jar:$JAVA_HOME/lib/tools.jar
·Login again
·Note
a. You need to change /usr/share/jdk1.6.0_14 to your jdk installation directory
b. Use a colon ":" to separate the paths under linux
c . $PATH / $CLASSPATH / $JAVA_HOME are used to refer to the value of the original environment variable.
When setting the environment variable, pay special attention not to overwrite the original value, which is a
common mistake.
d. The current directory "." in CLASSPATH cannot be lost. It is also a common mistake to lose the current directory.
e. export is to export these three variables as global variables.
f. Upper and lower case must be strictly differentiated.
2. Modify the .bash_profile file
This method is more secure. It can control the permissions to use these environment variables to the user level. If you need to give a user permission to use these environment variables, you only need to modify the .bash_profile file in the home directory of the individual user. .
·Open the .bash_profile file in the user directory with a text editor
·Add at the end of the .bash_profile file:
export JAVA_HOME=/usr/share/jdk1.6.0_14
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME /lib/dt.jar:$JAVA_HOME/lib/tools.jar
·Login again
3. Set variables directly under the shell This method is
deprecated , because if you change the shell, your settings will be invalid, so this method is only It is more troublesome for temporary use, and it is more troublesome to reset it when you want to use it later.
Just execute the following command in the shell terminal:
export JAVA_HOME=/usr/share/jdk1.6.0_14
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/ tools.jar
test jdk
1. Create a new Test.java file with a text editor, enter the following code in it and save it:public class test {
public static void main(String args[]) {
System.out.println("A new jdk test !") ;
}
}
2. Compile: execute the command javac Test.java
in the shell terminal 3. Run: execute the command java Test in the shell terminal
When the words "A new jdk test !" appear under the shell, the jdk is running normally.
uninstall jdk
Find the _uninst subdirectory of the jdk installation directory·Execute the command ./uninstall.sh in the shell terminal to uninstall jdk.
Reprinted: http://www.cnblogs.com/samcn/archive/2011/03/16/1986248.html