7

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.

Yang Bo
  • 245
  • 1
  • 3
  • 7
  • 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 08 '12 at 06: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 08 '12 at 07: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 08 '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 08 '12 at 22:57

2 Answers2

6

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.

Matej Kovac
  • 361
  • 3
  • 7
4

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

rwong48
  • 3
  • 2
didster
  • 799
  • 5
  • 5
  • 6
    /etc/profile is not executed by non-login shell – Yang Bo Oct 08 '12 at 08:06
  • 3
    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 08 '12 at 08:14