系统范围的$ PATH变量在哪里设置?


10

我正在使用Ubuntu Desktop 14.04,因此,我正在使用非登录外壳。当我打开GUI终端时,首先非登录Shell会话将读取以下启动文件:

/etc/bash.bashrc
~/.bashrc

非登录外壳程序从父进程继承环境,该父进程是一个登录外壳程序,因此会话还读取以下启动文件:

/etc/profile
~/.bash_profile

但是,我无法找到$PATH全系统的路径一样/bin/sbin/usr/bin/usr/sbin,在这些文件中的设置。$PATH这些目录的集合在哪里?

Answers:


16

PATH/etc/environment文件中设置了(默认)系统范围。

$ cat /etc/environment 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

基本上是保存全局环境变量的地方。


+1,但是您碰巧知道$PATH它是由父登录shell继承还是由每个bash实例重新加载?
kos 2015年

@kos所有的子进程,除非当然是在修改的环境中运行..从父shell继承环境
heemayl

我注意到外壳似乎没有扩展$HOME变量。例如,添加$HOME/.composer/vendor/binPATHin /etc/environment不会使该目录中的二进制文件在没有路径前缀的情况下执行。使用~/.composer/vendor/bin也不起作用。我发现有必要添加绝对路径,例如:/home/vagrant/.composer/vendor/bin。:这似乎与(虽然不解释这种行为)askubuntu.com/questions/402353/...
本·约翰逊

2
@BenJohnson那仅仅是因为/etc/environment(和~/.pam/environment)是由pam_envPAM模块读取的,而不是Shell或任何其他了解Shell /环境变量的东西;这同样适用于~扩张。因此,您需要在此处使用绝对路径。
heemayl
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.