Modifying environment variables in Linux and their effective methods

method one:  

        Add variables to the /etc/profile file [effective for all users and permanent]

        Use vi to add a variable in the file /etc/profile file, the variable will be valid for all users under Linux and is "permanent". To make the changes just now take effect immediately, you need to execute the following code.

# source /etc/profile

 

Method Two:  

        Add variables to the .bash_profile file in the user directory [effective for a single user and permanent]


        Use vi to add variables to the .bash_profile file in the user directory. The changes are only valid for the current user and are "permanent". To make the changes just now take effect immediately, you need to execute the following code in the user directory.

# source .bash_profile

 

Method three:  

        Directly run the export command to define variables [only valid for the current shell (BASH) and temporary]  

        Use [export variable name=variable value] to define a variable directly on the shell command line. The variable is only valid under the current shell (BASH) or its subshell (BASH). When the shell is closed, the variable is invalid. , when you open a new shell, there is no such variable. If you need to use it, you need to redefine it. Such as: export PATH=/usr/local/webserver/php/bin:$PATH  

 

Article source: http://www.2cto.com/os/201306/219701.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326608237&siteId=291194637
Recommended