在 CentOS(以及大多数 Linux 发行版)里,env(环境变量)本身是不能“刷新”的,只能通过重新加载配置文件或重新登录来让环境变量生效。下面按常见场景说明:
~/.bashrc(当前用户)source ~/.bashrc
或
. ~/.bashrc
~/.bash_profile 或 ~/.profilesource ~/.bash_profile
常见文件:
/etc/profile/etc/bashrc/etc/profile.d/*.sh执行:
source /etc/profile
或重新登录系统。
exec bash
这会重启当前 bash,重新加载环境变量。
env
或
printenv
export VAR_NAME=value
⚠️ 只在当前 shell 有效,退出后失效。
.bashrc,但用的是 非交互 shellsource,也没重新登录.sh 但没 export)如果是 systemd 服务:
systemctl daemon-reload
systemctl restart your_service
如果你能说清楚:
我可以给你更精确的命令。