大网数据广告活动
服务器运维问答

Where does the bash PATH on CentOS 7 get /usr/local/bin from?

· 52CE 我爱测

I've just spun up a brand new CentOS 7 VM (bash version 4.2.46) with Vagrant using the centos/7 box, and when I'm logged in as the vagrant user, this is my PATH: /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/vagrant/.lo…

问题原文

原帖链接 · Iain Hallam · CC BY-SA 3.0

I've just spun up a brand new CentOS 7 VM (bash version 4.2.46) with Vagrant using the centos/7 box, and when I'm logged in as the vagrant user, this is my PATH:

/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/vagrant/.local/bin:/home/vagrant/bin

When logged in as root, here's the PATH:

/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

I know that /etc/profile is adding /usr/local/sbin:/usr/sbin (at the end for most users, at the start for root), and the /etc/skel/.bash_profile that ends up in the vagrant home directory is adding /home/vagrant/.local/bin:/home/vagrant/bin, but where is the initial setting coming from?

At present I have no explanation of why users end up with /usr/local/bin:/usr/bin in their PATH, and root gets the others.

(Frankly, the ordering of the root PATH seems very odd, given that /usr/local/sbin and /usr/sbin should be at the end, according to /etc/profile.)

已采纳解答

原帖链接 · Schrute · CC BY-SA 3.0

In the bash source "config-top.h" has this:

/* The default value of the PATH variable. */
#ifndef DEFAULT_PATH_VALUE
#define DEFAULT_PATH_VALUE \
  "/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:."
#endif

/* The value for PATH when invoking `command -p'.  This is only used when
   the Posix.2 confstr () function, or CS_PATH define are not present. */
#ifndef STANDARD_UTILS_PATH
#define STANDARD_UTILS_PATH \
  "/bin:/usr/bin:/sbin:/usr/sbin:/etc:/usr/etc"
#endif

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-02-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。