在 Debian(以及大多数使用 systemd 的 Linux 发行版)里,所谓 “env 文件” 通常有两种场景,下面分别说明。
/etc/environment 或 unit 里的 EnvironmentFile=)/etc/environment这个文件 不是 shell 脚本,systemd 在启动时读取一次。
不会自动重载,需要:
# 重新加载 systemd 配置
systemctl daemon-reload
# 然后重启相关服务
systemctl restart your-service
⚠️ 已登录的 shell 不会自动生效,需要重新登录。
EnvironmentFile=例如:
[Service]
EnvironmentFile=/etc/default/myapp
修改后执行:
systemctl daemon-reload
systemctl restart myapp
✅ 这是“重载 env 文件”的标准做法。
.env、/etc/profile.d/*.sh)source /path/to/envfile
# 或
. /path/to/envfile
只要文件在:
~/.bashrc~/.profile/etc/profile.d/*.sh重新登录或:
exec bash
❌ 不要指望:
systemctl reload
能重载 env 文件(除非服务本身支持)
✅ env 变更通常需要:
daemon-reloadrestart servicegrep -R EnvironmentFile= /etc/systemd/system/
有结果 → systemd env
没有 → shell env
如果你能贴出:
我可以给你精确的重载命令。