Linux setting environment variables

Set environment variables

 

1. Execute export directly in the shell

 

After setting, it is only valid for the current terminal, other terminals cannot obtain this variable

 

 

 

2. Edit the .bash_profile file in the user's home directory, the variables defined in this file are only valid for the current user


 

add at the end 


 

 After saving, it is still not available in the current shell, you need to make the modification take effect, execute


 
 After the execution, the newly set variable can be obtained in the current shell, but still cannot be obtained in other shells. You need to execute the source command in another shell. The best way is to log out and log in or restart. 

 

 

 

3. Edit the /etc/profile file, the variables defined in this file are valid for all users


 

add at the end


 
 After saving, it is still not available in the current shell. You need to make the modification take effect, and

 you can obtain the newly set variables in the current shell by executing it, but it is still unavailable in other shells. You need to execute the source command in another shell. , the best way is to log out and log in or restart, 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326287364&siteId=291194637