环境变量¶
临时设置¶
仅对当前终端及其子进程生效:
持久设置¶
| 场景 | 常用位置 |
|---|---|
| 当前用户的交互式 Shell | ~/.bashrc 或 ~/.zshrc |
| 登录 Shell | ~/.bash_profile 或 ~/.profile |
| 所有用户的登录环境 | /etc/profile.d/*.sh |
| systemd 服务 | unit 文件的 Environment= 或 EnvironmentFile= |
修改 Shell 配置后重新打开终端,或执行:
不要把密码、Token、私钥等敏感信息写入仓库中的环境变量文件。服务端优先使用权限受控的 EnvironmentFile 或专用密钥管理方案。