Three ways to configure Java environment variables in a Linux system

Source: Internet
Author: User

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

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.