25

On Mac OS X, the default $PATH values are:

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

What are the default values on Linux?

1
  • default path is defined in config-top.h
    – user986805
    Mar 4, 2020 at 17:39

8 Answers 8

28

On a default Ubuntu desktop install $PATH is:

$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

But in a minimal chroot environment created by debootstrap, $PATH only contains:

# echo $PATH
/usr/sbin:/usr/bin:/sbin:/bin
13

Environment path values are stored in .bashrc file in ubuntu.

The system-wide PATH variable is defined in /etc/environment

2
  • 1
    Thanks -- I couldn't find where this file was actually sourced, but it appears to be included by PAM, in e.g. /etc/pam.d/login (and cron, su, etc) Jul 5, 2022 at 17:36
  • Great. I had my $PATH variable messed up and I just had to run source /etc/environment
    – Maf
    Jul 21, 2023 at 16:00
13

bash will set PATH to a hard-coded default value if it's not set in the environment:

$ env -i bash -c 'echo $PATH'
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.

We can check that this value is indeed hard-coded, and not read from the environment or some file, using the strings utility:

$ strings /bin/bash | grep /usr/sbin
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.

However, I get a different result on my Arch Linux machine:

$ env -i bash -c 'echo $PATH'
/usr/local/sbin:/usr/local/bin:/usr/bin

So, the default is chosen at the time the bash binary was built, which depends on the Linux distribution in use.

The bash man page states:

PATH

The search path for commands. It is a colon-separated list of directories in which the shell looks for commands (see COMMAND EXECUTION below). A zero-length (null) directory name in the value of PATH indicates the current directory. A null directory name may appear as two adjacent colons, or as an initial or trailing colon. The default path is system-dependent, and is set by the administrator who installs bash. A common value is /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin.

Here, "installs" likely refers to make install (as opposed to installing a pre-built binary using a package manager), so "administrator" would refer to the distribution vendor.

The "INVOCATION" section in the man page describes the startup process, which may affect the initial value of the variable.

2
  • 2
    This is the only answer that mentions the shell, and distributions. I stumbled upon the question because I'm sorting out PATH issues in ubuntu containers. And the "default path" will depend on the shell (bash, sh, etc.) and whether it's loaded interactively or not, and whether it's a login shell. It's not a simple answer. Kudos for mention of the hardcoded strings in the binary.
    – init_js
    Apr 9, 2019 at 22:31
  • And on some other Linux distros they seem to rely on this behaviour! I did some digging on Red Hat Enterprise Linux, and they do define a default path for csh, but not for bash. Crazy stuff! 😳 (I realize this has nothing to do with Ubuntu, but neither does the original question...)
    – traal
    May 22, 2023 at 13:53
8

There are path builtin the shells which is

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Then the default path for Ubuntu is:

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
4

Depending on which Linux your using, it might be different. If you have a login to a linux already, just type 'env' to see your environment variables.

If you want to know how the PATH env variable is getting built, have a look at .bashrc and .bash_profile in your home directory. If more curious, you can also look at /etc/profile, /etc/profile.d/* (if exists) and manual for bash (man bash).

3

There's an easy way to find out:

printenv

Or, more directly:

echo $PATH

But, if you're just looking for some quick info, Ubuntu typically sets the path to:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games:

For questions like this, you can usually dig up the answer by reading the Bible.

1
  • That's not always true because sometimes the PATH might appear messed up in this way. I'd look directly at /etc/environment as the ground truth.
    – Maf
    Jul 21, 2023 at 16:01
2

The canonical location seems to vary across distributions. With Debian 10, the system-default PATH is defined in /etc/login.defs. The default PATH for normal users is its ENV_PATH variable and the default for super-users is ENV_SUPATH. These will be used for sessions that don't spawn shells (e.g. cron jobs)

Other defaults may be defined by the per-shell scripts, including:

  • /etc/bash.bashrc
  • /etc/csh.cshrc
  • /etc/csh.login
  • /etc/profile
  • /etc/profile.d/*
2
  • What about /etc/environment?
    – Maf
    Jul 21, 2023 at 16:03
  • As I wrote, it varies across distributions.
    – David C.
    Jul 22, 2023 at 17:13
1

To see the default path use what other mentioned in answers:

echo $PATH

To edit use:

gedit ~/.bashrc

This default PATH variable are defined under /etc/enviroment.

1
  • That's not always true because sometimes the PATH might appear messed up in this way. I'd look directly at /etc/environment as the ground truth.
    – Maf
    Jul 21, 2023 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .