I am trying to find which file adds /opt/texbin folder to my PATH variable on Ubuntu. It is not present in my /etc/environment file. sudo grep -lr texbin . 2>/dev/null outputs nothing in the /etc folder. And still if I add set -x to the beginning of my /etc/zshenv file I can see that /opt/texbin is in my PATH before zsh sources this file.

Any ideas?

  • Is it in /etc/profile? – BenjiWiebe Jun 23 '14 at 17:45
  • Nope. I checked the file now and it's not in it, neither in any files in profile.d. Also as I said, grepping /etc folder gives nothing :/ – sencer Jun 23 '14 at 17:47
  • 1
    It is possible that it is due to a file in /etc, but not directly entered in the file, for instance if it gets /opt/texbin from the output of some other command and puts it in PATH. – BenjiWiebe Jun 23 '14 at 17:49
  • Makes sense. Couldn't think of a way of testing though -- can you? – sencer Jun 23 '14 at 17:51
  • I think I might be able to find it if I was sitting down at your computer, but I'm not sure.....How about giving me SSH access (with sudo access, of course)? :) – BenjiWiebe Jun 23 '14 at 17:52

I would try this approach to track down the source of /opt/texbin in your PATH variable:

  1. To get a list of files, which are actually read in (e.g. a non-standard file might be sourced by another file!), you can invoke zsh with the SOURCE_TRACE option enabled:

    $ zsh -o sourcetrace
    +/etc/zshenv:1> <sourcetrace>
    +/home/user/.zshrc:1> <sourcetrace>
    +/home/user/.zcompdump:1> <sourcetrace>
    +/home/user/.zshrc-last:1> <sourcetrace>
  2. Check these files, where the PATH variable come into play:

    $ grep -ie "path.*=" files_from_step_1

    The case insensitivity is crucial, since zsh uses the array $path, which automatically gets converted to the bash-like colon-separated list $PATH and vice versa.

  3. If still not lucky, try to include a debug message in /etc/zshenv, where commands are first read from:

    print -l $path

    This will give you a nice list of the PATH variable, which zsh inherits from its parent process (display manager, init process, etc.).*

  4. If the path is indeed inherited from the starting process, it is crucial to know which processes are relevant:

    $ pstree -apH $$

    This produces a process tree, where the shell process (pid in $$) is highlighted. Check the config files for these processes, too, and keep in mind that

    • source /some/file or . /some file can also alter the PATH
    • if you edit e.g. /etc/profile in your current console, log off and log in again, the parent process (X logon manager) might still have the old environment.+

* As you have written, the PATH already contains /opt/texbin before /etc/zshenv is read, checked by set -x in /etc/zshenv. I get no output with this technique, but with my step 3, hence I included the other steps in my answer as well.

+Suffered myself badly due to this behavior some time ago...


The correct way to activate execution trace or source trace at the time /etc/zshenv is loaded is to activate it at the shell command: zsh -l -o xtrace, zsh -l -o sourcetrace -- be sure to try with the -l option, since the path element might only be added at login.

Beside this, if you are still getting a path element added before /etc/zshenv is loaded, you could check for a ~/.pam_environment file. This is the user-local version of the /etc/environment file and is loaded at about the same time, before the shell or user environment. Check the man page "pam_env" for more details about the format used - it is different for the user file.

One other minor possibility is the ENV environment variable. When a SH-compatible shell is started in SH-compatible mode, the file whose path is in ENV is loaded as a startup file before anything else. Search your shell's documentation for more detail. login.defs is also used at login and by various user/login utilities, but /etc/environment is the standard for all modern login systems and is prefered for establishing the PATH variable.


The PATH variable that is passed to your shell at log-in is defined in /etc/login.defs. There are two setups here, ENV_SUPATH and ENV_PATH. Depending if you login as root or as a user, one of the two is passed to the shell via the environment variable PATH. After the PATH variable is passed to the shell, any additional changes are controlled by the shell's start-up scripts.

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.