温馨提示×

centos env怎么重载

小樊
46
2026-09-15 09:59:04
栏目: 智能运维

在 CentOS 里,“env 重载”一般分几种场景,下面按常见情况说明:


1. 修改了 /etc/profile 或 ~/.bash_profile 后重载

source /etc/profile
# 或
. ~/.bash_profile

只对当前 shell 生效。


2. 修改了 /etc/environment

这个文件不是 shell 脚本,不能 source。
需要:

  • 重新登录
  • 或重启系统

3. 使用 systemd 的环境变量

如果你改了:

  • /etc/environment
  • /etc/systemd/system.conf
  • service 里的 Environment

需要:

systemctl daemon-reexec
# 或
systemctl daemon-reload

然后重启相关服务:

systemctl restart xxx

4. 当前 shell 临时重载环境变量

exec bash

会重新启动一个 bash,读取配置。


5. 查看当前环境变量

env
# 或
printenv

如果你能说清楚是 哪种 env(用户 / 系统 / systemd / Docker),我可以给你更精确的操作。

0 踩