添加环境变量:http://www.javashuo.com/article/p-ynsbmyob-cv.htmlhtml
1、环境变量介绍:
在Linux系统中,环境变量按照其做用范围不一样大体能够分为系统级环境变量和用户级环境变量。linux
天然而然地,环境变量的配置文件也相应的被分红了系统级和用户级两种。shell
2、系统级:ubuntu
一、/etc/profile
在系统启动后第一个用户登陆时运行,并从/etc/profile.d目录的配置文件中搜集shell的设置,使用该文件配置的环境变量将应用于登陆到系统的每个用户。bash
提示:在Linux系统中,使用如下命令可使配置文件马上生效。session
source /etc/profile echo $PATH
二、/etc/bashrc(Ubuntu和Debian中是/etc/bash.bashrc)
在 bash shell 打开时运行,修改该文件配置的环境变量将会影响全部用户使用的bash shell。spa
注意:这里的bash shell有不一样的类别,不一样的类别所使用的环境变量配置文件也有所不一样。翻译
通常状况下,非登陆shell不会执行任何profile文件,非交互shell模式不会执行任何bashrc文件。code
三、/etc/environment
在系统启动时运行,用于配置与系统运行相关但与用户无关的环境变量,修改该文件配置的环境变量将影响全局。htm
3、用户级:
一、~/.profile(推荐首选)
~/.profile: executed by Bourne-compatible login shells.
当用户登陆时执行,每一个用户均可以使用该文件来配置专属于本身使用的shell信息。
二、~/.bashrc
~/.bashrc: executed by bash(1) for non-login shells.
当用户登陆时以及每次打开新的shell时该文件都将被读取,不推荐在这里配置用户专用的环境变量,由于每开一个shell,该文件都会被读取一次,效率确定受影响。
生效用:source
bashrc和profile的差别
从上面的英文描述能够知道,bashrc和profile的差别在于:
注意:一般咱们修改bashrc,有些linux的发行版本不必定有profile这个文件;
三、~/.bash_profile 或 ~./bash_login
~/.bash_profile or ~./bash_login - If one of these file exist, bash executes it rather then "~/.profile"
when it is started as a login shell. (Bash will prefer "~/.bash_profile" to "~/.bash_login").
However, these files won't influence a graphical session by default.
以上是ubuntu官网给出的关于~/.bash_profile 和 ~./bash_login 的说明,翻译为中文:
~/.bash_profile 或 ~./bash_login -
若是有其中的一个文件存在的话, 当启动的是一个登陆shell时,Bash 会执行该文件而不会执行~/.profile ;
若是两个文件都存在的话,Bash 将会优先执行~/.bash_profile 而不是~/.bash_login ;
然而, 默认状况下,这些文件不会影响图形会话。
四、~/.bash_logout
当每次退出系统(退出bash shell)时执行该文件。
注意:Linux系统使用 $VARIABLE_NAME 访问环境变量,多个环境变量之间使用 “:”分隔,Windows系统使用 %VARIABLE_NAME% 访问环境变量,多个环境变量之间使用 ; 分隔。
4、执行顺序
通常状况下,Linux加载环境变量配置文件的执行顺序为:
==> /etc/profile ==> ~/.bash_profile | ~/.bash_login | ~/.profile ==> ~/.bashrc ==> /etc/bashrc ==> ~/.bash_logout