I installed some programs in /opt/my-program/bin, I wanted to add /opt/my-program/bin to system $PATH for all users's non-login shell and login shell. What should I do?

Changing /etc/environment is OK for non-login shell, but it does not work for login shell because Debian's /etc/profile (which will be sourced by login shell) will override the $PATH specified in /etc/environment.

  • If it's just a couple of binaries you want people to have access to, you can just symlink them to /usr/local/bin without altering environment variables. – jordanm Oct 8 '12 at 6:53
  • Symlinks does not work because the files in /opt/my-program/bin use some shell script like cd $(basedir "$0"). Symlinks cause $0 changes. – Yang Bo Oct 8 '12 at 7:02
  • @user955091 I'd consider that a bug in the program. The standard technique is to look at the symlink target in such a case, precisely so that you can symlink the program in /usr/local/bin or ~/bin. – Gilles 'SO- stop being evil' Oct 8 '12 at 22:56
  • 1
    Why not remove the assignment of PATH in /etc/profile (at least for non-root users)? – Gilles 'SO- stop being evil' Oct 8 '12 at 22:57

Make /etc/profile source /etc/bash.bashrc by adding [ -f /etc/bash.bashrc ] && . /etc/bash.bashrc to the end of /etc/profile, then add your path changes to /etc/bash.bashrc with PATH=$PATH:/some/other/path

| improve this answer | |
  • 4
    /etc/profile is not executed by non-login shell – Yang Bo Oct 8 '12 at 8:06
  • 1
    I know - but bash.bashrc is which is why the path change should be added there and then make /etc/profile source /etc/bash.bashrc to make the changes for login shells as well. – didster Oct 8 '12 at 8:14

The /etc/login.defs file contains a default path as follows:

ENV_SUPATH      PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV_PATH        PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

Some of the variables are moving to the pam modules, but the /bin/login still has it's config file independent of users' shell.

| improve this answer | |

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.