Article Title: three methods for setting Linux environment variables. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
1. Linux variable types
Linux variables are divided by the life cycle of variables. There are two types of Linux variables:
1. Permanent: the configuration file needs to be modified, and the variable takes effect permanently.
2. Temporary: Use the export command to declare the variable. The variable becomes invalid when the shell is closed.
2. Three Methods for setting Variables
1. Add the variable in the/etc/profile file [effective for all users (permanent )]
Use VI to add a variable to the/etc/profile file. This variable will be valid for all users in Linux and will be "permanent ".
For example, edit the/etc/profile file and add the CLASSPATH variable.
# Vi/etc/profile
Export CLASSPATH =./JAVA_HOME/lib; $ JAVA_HOME/jre/lib
Note: to change the file to take effect immediately, run # source/etc/profile. Otherwise, it will only take effect the next time you re-enter the user.
2. Add the variable [effective for a single user (permanent)] To the. bash_profile file in the user directory )]
Use VI to add a variable to the. bash_profile file in the user directory. The change volume is valid only for the current user and is "permanent ".
For example, edit the. bash_profile under the guok user directory (/home/guok ).
$ Vi/home/guok/. bash. profile
Add the following content:
Export CLASSPATH =./JAVA_HOME/lib; $ JAVA_HOME/jre/lib
Note: to change the file to take effect immediately, run $ source/home/guok/. bash_profile. Otherwise, it will only take effect the next time you re-enter the user.
3. Run the export command directly to define the variable [only valid for the current shell (BASH) (Temporary )]
Use the [export variable name = variable value] to define a variable under the shell command line. This variable is valid only in the current shell (BASH) or its subshell (BASH, when shell is closed, the variable becomes invalid. This variable is not available when a new shell is opened. You need to define the variable again if necessary.