linux set java environment

Linux configuration java environment variables (detailed) 
1. 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 A protocol will appear. , continue to press Enter, when asked whether to 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. 2. 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. Three ways to configure environment  variables to security issues.  



 






·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 is used to refer to the value of the original environment variable. 
When setting the environment variable, special attention should be paid not to overwrite the original value. This 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. It is safer to modify the .bash_profile file . It can control the permission 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 user's home directory. .bash_profile file on it. ·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 

· Log in again 

3. Direct Setting variables under the shell is 
not recommended to use this method, because if you change the shell, your settings will be invalid, so this method is only used temporarily, and it is more troublesome to set it again 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 

4. 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. 

5. Uninstall jdk ·Find the _uninst subdirectory of the jdk installation directory  ·Execute the command ./uninstall.sh in the shell terminal to uninstall jdk. 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327010873&siteId=291194637