Linux operating system three ways to configure environment variables

  

Now more and more friends using Linux, development under Linux is the first need to configure environment variables, the following three examples of configuration java environment variables The method of the environment variable.


1. Modify the /etc/profile file

This method is recommended if your computer is only used for development, because all users have the right to use the shell. These environment variables can cause security problems in the system.


(1) Open /etc/profile with a text editor


(2) Add at the end of the profile:

JAVA_HOME=/usr/share/jdk1.5.0_05

PATH=JAVA H OME/bin: PATH

CLASSPATH=.:JAVA H OME/lib/dt.jar: JAVA_HOME/lib /tools.jar

export JAVA_HOME

export PATH

export CLASSPATH


(3) Re-login


Annotation:

a. You should change /usr/share/jdk1.5.0_05jdk to your jdk installation directory


b. Linux uses the colon ":" to separate the path


c. PATH/CLASSPATH /$JAVA_HOME is used to reference the value of the original environment variable, especially when setting environment variables Note that the original value cannot be overwritten. This is a common mistake.


d. The current directory in the CLASSPATH “.” can not be dropped, the current directory is also a common mistake.


e. export is to export these three variables as global variables.


f. Cases must be strictly distinguished.


2. Modifying the .bashrc file

This method is more secure, it can control the permissions of using these environment variables to the user level, if you need to give User permissions use these environment variables, you only need to modify the .bashrc file in their personal user's home directory.


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


(2) Add at the end of the .bashrc file: < Br>

set JAVA_HOME=/usr/share/jdk1.5.0_05

export JAVA_HOME

set PATH=JAVA H OME/bin: PATH

export PATH < Br>

set CLASSPATH=.:JAVA H OME/lib/dt.jar: JAVA_HOME/lib/tools.jar

export CLASSPATH


(3) Re-login


3. Setting variables directly in the shell

This method is deprecated, because changing the shell, your settings are invalid, so this method It is only temporary use, and it needs to be reset when it is used later. It is more troublesome.


Execute the following commands in the shell terminal:

export JAVA_HOME=/usr/share/jdk1.5.0_05

export PATH=JAVA H OME/bin: PATH

export CLASSPATH=.:JAVA H OME/lib/dt.jar: JAVA_HOME/lib/tools.jar

Copyright © Windows knowledge All Rights Reserved