12

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?

17

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
3

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
3

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

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

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.

2

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).

2

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, it looks like this default is chosen at the time the bash binary was built, which depends on the Linux distribution in use.

  • 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 '19 at 22:31
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.