Three ways to configure Java environment variables in a Linux system:
1. Modify the/etc/profile file
If your computer is only recommended for development use, because all users ' shells have the right to use these environment variables, it may pose a security problem for the system.
(1) Open/etc/profile with a text editor
(2) At the end of the profile file, add:
Java_home=/usr/share/jdk1.5.0_05
Path= $JAVA _home/bin: $PATH
Classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar
Export Java_home
Export PATH
Export CLASSPATH
(3) Re-login
Annotations:
A. You want to change the/USR/SHARE/JDK1.5.0_05JDK to your JDK installation directory
B. Linux with colon ":" to separate the path
C. $PATH/$CLASSPATH/$JAVA _home is used to refer to the value of the original environment variable, especially when setting the environment variable to be careful not to overwrite the original value, this is a common mistake.
D. Classpath current directory "." Can not be lost, the current directory to throw away is also a common mistake.
E. Export is the exporting of these three variables to global variables.
F. Capitalization must be strictly differentiated.
2. Modify the. bashrc file
This method is more secure, it can control the use of 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 their own user's home directory of the. bashrc file.
(1) Using a text editor to open the. bashrc file in the user directory
(2) by adding at the end of the. bashrc file:
Set java_home=/usr/share/jdk1.5.0_05
Export Java_home
Set path= $JAVA _home/bin: $PATH
Export PATH
Set classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar
Export CLASSPATH
(3) Re-login
3. Set the variables directly under the shell
Do not agree to use this method, because the shell, your settings are invalid, so this method is only temporary use, later to use the time to reset, more trouble.
Just execute the following command at the shell Terminal:
Export java_home=/usr/share/jdk1.5.0_05
Export path= $JAVA _home/bin: $PATH
Export classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar