<title>Settings for JDK environment variables under Linux (three ways to configure environment variables)</title> Settings for JDK environment variables under Linux (three ways to configure environment variables) ① 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.
vi /etc/profile
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
You can choose to log in again after the modification is complete, or you can use
source /etc/profile
or a
. /etc/profile
(Note that the number is followed by a space), and the last two methods have the same effect after the modification.
Description
A. You want to change/USR/SHARE/JDK1.5.0_05JDK to your JDK installation directory
B. Use the 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 environment variables in particular, it is important to note that the original value can not be overwritten, which 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.
② modifying. bashrc files
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.
vi ~/.bashrc
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
③ setting 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
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
Open terminal after completion, type the command java -version
, if the version information of the JDK appears, the environment variable configuration is successful.
Hadoop Build Notes: Setting of JDK environment variables under Linux (three ways to configure environment variables)