🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## **一、/etc/environment vs /etc/profile** /etc/profile是shell如bash进程的配置文件,配置环境变量的语法为 export KEY=VALUE /etc/environment是为所有进程进行设置的,配置环境变量的语法为 KEY=VALUE ## **二、/etc/profile vs /etc/bashrc vs ~/.profile等** 这些文件都是shell/bash进程在初始化时可能会读取的文件,根据 [此图](http://www.solipsys.co.uk/new/BashInitialisationFiles.html),来决定要读取哪些文件: ![](https://img.kancloud.cn/de/54/de543b42e7613c121455d8bfc4a7e116_611x640.png) 要弄懂上面的流程,需要知道下面的背景知识 #### **2.1 bash的login vs non-login,以及interactive以及non-interactive** 参考如下两篇文章 https://zhuanlan.zhihu.com/p/509203831 https://tecadmin.net/difference-between-login-and-non-login-shell ## **三、FAQ** Q:为什么在linux上安装go,并把`/usr/local/go/bin`目录在`/etc/profile`文件中,增加一行`export PATH=$PATH:/usr/local/go/bin`,在执行`sudo go get ..`命令时,提示找不到go命令? A:sudo命令查找的PATH是`/etc/sudoers`中的如下一行决定的 ``` Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin ``` 参考:https://techkluster.com/linux/sudo-command-not-found/ ## **四、参考** * https://zhuanlan.zhihu.com/p/509203831 * https://stackoverflow.com/questions/18791486/differences-uses-and-similarities-between-bashrc-bash-profile-and-etc-profil * http://blog.itpub.net/27040306/viewspace-732343/ * https://www.ibm.com/docs/sr/aix/7.2?topic=files-etcenvironment-file * https://www.stefaanlippens.net/bashrc_and_others/ * https://tecadmin.net/difference-between-login-and-non-login-shell/#:~:text=A%20Bash%20shell%20can%20be%20either%20a%20login,user%2C%20the%20first%20shell%20is%20the%20login%20shell.