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?
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
Environment path values are stored in .bashrc file in ubuntu.
The system-wide PATH variable is defined in /etc/environment
source /etc/environment
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.
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
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).
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.
/etc/environment
as the ground truth.
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:
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
.