如何在 Linux 中设置系统范围的环境变量
在 CentOS 或 RHEL 上设置系统范围的环境变量
在基于 RHEL 的 Linux 中,当用户登录时,登录 shell 会执行 /etc/profile
脚本。该脚本为系统范围内的所有用户自定义环境变量。脚本 /etc/profile
还获取位于 /etc/profile.d
目录中的所有脚本。因此,为了在基于 RHEL 的 Linux 中设置系统范围的环境变量,您可以在 /etc/profile.d
中创建一个扩展名为 .sh 的自定义文件,如下所示。
$ sudo vi /etc/profile.d/proxy.sh
export http_proxy=http://my.proxy.com:8000
export https_proxy=http://my.proxy.com:8000
如果代理需要身份验证,您也可以指定用户名和密码。
export http_proxy=http://username:[email :8000
export https_proxy=http://username:[email :8000
在 Ubuntu 或 Debian 上设置系统范围的环境变量
基于 Debian 的系统不使用 /etc/profile.d
目录。因此,为了在 Ubuntu 或 Debian 中设置系统范围的环境,您可以使用 /etc/environment
来代替。
$ sudo vi /etc/environment
http_proxy=http://my.proxy.com:8000
https_proxy=http://my.proxy.com:8000
对于具有身份验证的代理:
http_proxy=http://username:[email :8000
https_proxy=http://username:[email :8000