Hadoop Build Notes: Setting of JDK environment variables under Linux (three ways to configure environment variables)

Source: Internet
Author: User

<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/profileor 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)

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.