跳转至

环境变量

临时设置

仅对当前终端及其子进程生效:

export APP_ENV=production
export PATH="$HOME/bin:$PATH"
echo "$APP_ENV"

持久设置

场景 常用位置
当前用户的交互式 Shell ~/.bashrc~/.zshrc
登录 Shell ~/.bash_profile~/.profile
所有用户的登录环境 /etc/profile.d/*.sh
systemd 服务 unit 文件的 Environment=EnvironmentFile=

修改 Shell 配置后重新打开终端,或执行:

source ~/.bashrc

不要把密码、Token、私钥等敏感信息写入仓库中的环境变量文件。服务端优先使用权限受控的 EnvironmentFile 或专用密钥管理方案。