源码安装的服务默认不在 PATH 里,统一在 /etc/profile 末尾追加即可:
export PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
export PATH=/opt/cmake/bin:$PATH
export PATH=/usr/local/git/bin/:$PATH
export PATH=$PATH:/usr/local/node/bin
export PATH=/usr/local/php/bin:/usr/local/php/sbin:$PATH
export PATH=/usr/local/redis/bin:$PATH
export PATH=/usr/local/nginx/sbin:$PATH
修改后执行 source /etc/profile 生效。
注意事项
- 顺序决定优先级:
PATH=$PATH:/xxx表示系统目录优先,PATH=/xxx:$PATH表示自定义目录优先。源码升级系统自带软件(如 Git)时,要让新路径排在前面或直接卸载旧版本。 - 只对当前 shell 生效的写法是
export PATH=...,写入/etc/profile才对所有用户持久生效;仅当前用户可写~/.bash_profile或~/.zshrc。 - 若用 systemd 托管服务,
/etc/profile不会被读取,需要在 service 文件里用Environment=或写绝对路径。