How to configure environment variables in Linux

Source: Internet
Author: User
& Nbsp; now more and more friends are using linux. in linux development, environment variables need to be configured first. The following describes how to configure the java environment variables. 1. modify the/etc/profile File. if your computer is only used for development, this method is recommended because  

Now there are more and more friends using linux. for development in linux, environment variables need to be configured first. The following describes three methods to configure environment variables using java environment variables.

1. modify the/etc/profile file

This method is recommended if your computer is used only for development, because all users' shells have the right to use these environment variables, which may bring security issues to the system.

(1) open/etc/profile in a text editor

(2) add the following content to the end of the profile file:

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) log on again

Note:

A. change/usr/share/jdk1.5.0 _ 05jdk to your jdk installation directory.

B. use the colon ":" to separate paths in linux

C. $ PATH/$ CLASSPATH/$ JAVA_HOME is used to reference the value of the original environment variable. when setting the environment variable, pay special attention not to overwrite the original value, this is a common error.

D. The current directory "." in CLASSPATH cannot be lost. it is also a common error to discard the current directory.

E. export exports the three variables as global variables.

F. Case sensitivity is required.

2. modify the. bashrc file

This method is more secure. it can control the permissions to use these environment variables to the user level. if you need to grant a user permission to use these environment variables, you only need to modify. you can use the bashrc file.

(1) open the. bashrc file in the user directory in a text editor.

(2) add the following content to 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) log on again

3. directly set variables in shell

I am not in favor of using this method. if you change the shell, your settings will be invalid. Therefore, this method is only for temporary use and will be re-set later, which is troublesome.

Run the following command on 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

Related Article

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.