Linux Configuration Java Environment variables (verbose)

Source: Internet
Author: User

Linux Configuration Java Environment variables (verbose)
I. Unpacking and installing the JDK
Enter the directory where the Jdk-6u14-linux-i586.bin file is located under the shell terminal,
Executes the command./jdk-6u14-linux-i586.bin at this point there will be a protocol, even after hitting enter, when asked whether to agree, enter Yes, return. A jdk1.6.0_14 directory is then generated under the current directory, and you can copy it to any directory.

Two. Environment variables that need to be configured
1. Path environment variable. The function is to specify the command search path, and when executing the command under the shell, it looks in the path specified by the path variable to see if the appropriate command program can be found. We need to add the bin directory in the JDK installation directory to the existing path variable, and the bin directory contains the frequently used executables such as Javac/java/javadoc wait, and after setting the path variable, you can execute the Javac/java tool in any directory.
2. CLASSPATH environment variables. The role is to specify the class search path, to use the already written classes, the premise is to be able to find them, the JVM is through the classpth to find the class. We need to set the Dt.jar and Tools.jar in the Lib subdirectory of the JDK installation directory to classpath, of course, the current directory "." must also be added to the variable.
3. Java_home environment variables. It points to the JDK's installation directory, and software such as Eclipse/netbeans/tomcat finds and uses the installed JDK by searching for java_home variables.

three. Three ways to configure environment variables1. Modify the/etc/profile file
This approach is recommended if your computer is used only as a development, because all user shells have the right to use these environment variables, which can pose a security issue for the system.
• Open/etc/profile with a text editor
• At the end of the profile file, add:
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
• annotations
A. You want to change/usr/share/jdk1.6.0_14 to your JDK installation directory
B. Use the colon ":" to separate the paths under Linux
C. $PATH/$CLASSPATH/$JAVA _home is the value used to refer to the original environment variable
When setting environment variables, be careful not to overwrite the original value, which is a
A common error.
D. Current directory in Classpath "." It is a common mistake to throw away the current directory.
E. Export is exporting these three variables as global variables.
F. The case must be strictly differentiated.

2. Modify the. bash_profile file

This method is more secure, it can control the use of these environment variable permissions to the user level, if you need to give a user permissions to use these environment variables, you only need to modify their personal user home directory of the. bash_profile file on it.
• Open the. bash_profile file in the user directory with a text editor
• At the end of the. bash_profile file, add:

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
Do not support the use of this method, because the shell, your settings are invalid, so this method is only temporary use, and later to use the time to reset, more trouble.
Simply execute the following command at 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

four. Test the JDK
1. Create a new Test.java file with 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. Compile: Execute command at Shell Terminal Javac Test.java
3. Run: Execute command Java Test at Shell Terminal
When the shell appears under "A New JDK test!" The JDK runs normally.

Five. Uninstalling the JDK
• Locate the _uninst subdirectory of the JDK installation directory
• Execute commands at the shell terminal./uninstall.sh You can uninstall the JDK.

Linux Configuration Java Environment variables (verbose)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.