Direct implementation process:
1. Unzip and install jdk
Enter the directory where the jdk-6u14-linux-i586.bin file is located in the shell terminal.
Execute the command ./jdk-6u14-linux-i586.bin. At this time, a protocol will appear, and you will continue to press Enter. When asking whether you agree, enter yes and enter. Then a jdk1.6.0_14 directory will be generated in the current directory, and you can copy it to any directory.
2. Environment variables that need to be configured
1. PATH environment variable. The function is to specify the command search path. When executing the command under the shell, it will search in the path specified by the PATH variable to see if the corresponding command program can be found. We need to add the bin directory under the jdk installation directory to the existing PATH variable. The bin directory contains the frequently used executable files such as javac/java/javadoc waiting. After setting the PATH variable, you can use it in any directory Execute javac/java and other tools.
2. CLASSPATH environment variable. The function is to specify the class search path. You need to use already written classes. The premise is of course that you can find them. 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 installation directory of jdk. Eclipse/NetBeans/Tomcat and other software find and use the installed jdk by searching for JAVA_HOME variables.
Three ways to configure environment variables
1. Modify /etc/profile file
This method is recommended if your computer is only used as development because all user shells have the right to use these environment variables, which may cause security issues to the system.
・Use a text editor to open /etc/profile
・Add to 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
・Re-login
·annotation
a. You want to change /usr/share/jdk1.6.0_14 to your jdk installation directory
b. Use colon ":" to separate paths under linux
c. $PATH / $CLASSPATH / $JAVA_HOME is used to refer to the value of the original environment variable. When setting the environment variable, you should pay special attention to not overwriting the original value. This is a common mistake.
d. The current directory "." in CLASSPATH cannot be lost, and it is also a common mistake to throw away the current directory.
e. export is to export these three variables as global variables.
f. The upper and lower case must be strictly distinguished.
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 certain user permission to use these environment variables, you only need to modify the .bash_profile file in its own user home directory. It's right.
・Use a text editor to open the .bash_profile file in the user directory・Add to 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
・Re-login
3. Set variables directly under the shell <br />I don't like using this method because if you change the shell, your settings will be invalid. Therefore, this method is only temporarily used. You need to reset it when you want to use it in the future. trouble.
Simply 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
4. Test jdk
1. Create a new Test.java file using a text editor, enter the following code and save it:
public class test { public static void main(String args[]) { System.out.println("A new jdk test !"); } }
2. Compilation: 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, jdk runs normally.
5. Uninstall jdk
Find the _uninst subdirectory of the jdk installation directory and execute the command ./uninstall.sh in the shell terminal to uninstall jdk.
Is it based on the above process that we have implemented the configuration of Java environment variables under Linux? I hope it can be helpful to everyone's learning.