1. 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.
(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 the colon ":" to separate the path C. $PATH/$CLASSPATH/$JAVA _home is used to refer to the value of the original environment variable, when setting the environment variable is particularly important to be careful not to overwrite the original value, this is a common mistake. 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. bashrc 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. bashrc file on it.
(1) Open the. bashrc file in the user directory with a text editor
(2) At the end of the. bashrc file, add:
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 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.5.0_05 export path= $JAVA _home/bin: $PATH
Linux Configuration example: Configuring Java Environment variables