How to add a path to system $PATH for all users's non-login shell and login shell on debian

6,258

Solution 1

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

Solution 2

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.

Share:
6,258

Related videos on Youtube

Yang Bo
Author by

Yang Bo

Updated on September 18, 2022

Comments

  • Yang Bo
    Yang Bo over 1 year

    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.

    • jordanm
      jordanm over 11 years
      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.
    • Yang Bo
      Yang Bo over 11 years
      Symlinks does not work because the files in /opt/my-program/bin use some shell script like cd $(basedir "$0"). Symlinks cause $0 changes.
    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' over 11 years
      @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'
      Gilles 'SO- stop being evil' over 11 years
      Why not remove the assignment of PATH in /etc/profile (at least for non-root users)?
  • Yang Bo
    Yang Bo over 11 years
    /etc/profile is not executed by non-login shell
  • didster
    didster over 11 years
    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.