Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a line in my $PATH that is invalid and want to delete it, but I'm not sure where it's coming from. It's not being set in .bashrc, .profile, or /etc/environment.

Is there any way to figure out its source? Thanks!

share|improve this question

Environment variables should be set in either /etc/environment or /etc/profile, or their equivalent per-user files ~/.pam_environment or ~/.profile. Since you've checked /etc/environment and ~/.profile, check /etc/profile (and note that it sources files in /etc/profile.d/). There's no ~/.pam_environment by default.

If the bad PATH gets set by bash, you can start bash as an interactive login shell, with xtrace enabled, bash -xil, to help pinpoint the place where it happens.

EDIT: With more useful output and pipe to less:

PS4='+ $BASH_SOURCE:$LINENO: ' bash -xilc '' 2>&1 | less
share|improve this answer
Thanks geirha, I checked /etc/profile and nothing there either. So I tried bash -xil which is very cool, but scrolls several screens worth of output, and piping it to more doesn't pause them. Is there any way to capture that output so I can look through it? – Kurtosis Mar 17 '12 at 21:47
It's output on stderr, so you have to redirect stderr to the pipe, but even then it won't work right, since bash is attempting to communicate with the terminal, so let's tell it to run an empty script to make it exit immediately. -c ''. Also, we can have it output filename and line numbers too by changing PS4. PS4='+ $BASH_SOURCE:$LINENO: ' bash -xilc '' 2>&1 | less – geirha Mar 17 '12 at 22:21

/etc/environment should set the PATH variable defaults. I recommend to have a look, maybe this file was modified on your system. A workaround could be to unset the PATH variable and to "re-set" it each time you login.

share|improve this answer

I got frustrated with the bloated ~/.bashrc that is installed! i deleted it and made a minimal version that sets the PATH and aliases ls, all that other stuff i dont need. perhaps you want to start from scratch?

share|improve this answer
Something is adding to his PATH and he doesn't know what. Making a new bashrc would not solve this problem. – Chan-Ho Suh Mar 15 '12 at 22:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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