1、设置环境变量的三种方法
(1)、export---------临时设置,也就是对当前会话生效
eg:export LANG=en_US
(2)、写.bash_profile文件(.bash_profile的位置一般在$HOME目录下)------对当前用户设置有效
vi .bash_profile
要立即生效,请使用 source .bash_porfile
(3)、写/etc/profile文件------对全局的所有用户设置有效
vi /etc/profile
要立即生效,请使用 source .profile
2、众多profile的执行顺序
/etc/profile >>> .bash_profile >>> .bashrc >>> /etc/bashrc >>> .bash_logout
(1) /etc/profile: 此文件为系统的全局环境变量,当用户第一次登录时,该文件被执行。并从/etc/profile.d目录的配置文件中搜集shell的设置。
(2) .bash_profile: 单个用户的环境变量设置。
(3) .bashrc: 该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该该文件被读取。
(4) /etc/bashrc: 为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取(即每次新开一个终端,都会执行bashrc)。
(5) .bash_logout: 当每次退出系统(退出bash shell)时,执行该文件。另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承 /etc/profile中的变量,他们是"父子"关系。