Find the answer to your Linux question:
Results 1 to 7 of 7
While the setting of the PATH variable is sometimes set in /etc/profile, it is not the only source of path information. However whilst changing it there inside the script it ...
  1. #1
    Just Joined!
    Join Date
    Apr 2007
    Posts
    3

    Question PATH Debian Etch

    While the setting of the PATH variable is sometimes set in /etc/profile, it is not the only source of path information.

    However whilst changing it there inside the script it does not change it in the user's PATH.

    Having installed java 1.6 from sun I would like to add the ../bin directory to the path, and later other things to the PATH.

    So what is the source hierarchy of PATH or $PATH

    Many thanks
    Regards
    Keith

  2. #2
    Linux Engineer Zelmo's Avatar
    Join Date
    Jan 2006
    Location
    Riverton, UT, USA
    Posts
    1,001
    /etc/bash.bashrc is meant to be sourced by /etc/profile, if the sysadmin so chooses (in Debian it's left alone by default). Likewise, ~/.bashrc gets sourced by ~/.bash_profile. So /etc/profile is the authoritative file for system-wide bash settings, and ~/.bash_profile is the final word for user-specific settings.

    As to why the users' paths aren't changing, a few possibilities come to mind:
    1. The PATH variable was altered after the "export $PATH" statement in /etc/profile, so it isn't exported and thus doesn't apply to other terminal sessions.
    2. The PATH is being altered while the user's session is already open, so the user's shell is unaware of the changes until you explicitly source the altered /etc/profile.
    3. There are two PATH settings in /etc/profile, both under an "if" statement that checks whether the user is root. You might be altering only root's path (the first one).
    Stand up and be counted as a Linux user!

  3. #3
    Just Joined! tuxv's Avatar
    Join Date
    Jul 2006
    Location
    Colombo, Sri Lanka
    Posts
    92
    You can set the path by following these easy steps

    open up a terminal and type
    Code:
     export PATH=/path_to_jdk/jdk/bin:$PATH
    if you want the PATH to be stored for your user for ever
    Code:
    nano ~/.bashrc
    and then add that above line to the end of that file and save it.

    hope this will help you

  4. #4
    Just Joined!
    Join Date
    Apr 2007
    Posts
    3

    Question

    People

    Thank you for your suggestions so far, I think we are getting closer.

    More research and the following files suggest that there is another agent at work.
    I look forward to your suggestions

    #+++++++++++++++++++++++++++
    # /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
    # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

    if [ "`id -u`" -eq 0 ]; then
    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/jdk1.6.0_01/bin"
    else
    PATH="/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/local/jdk1.6.0_01/bin"
    fi

    if [ "$PS1" ]; then
    if [ "$BASH" ]; then
    PS1='\u@\h:\w\$ '
    else
    if [ "`id -u`" -eq 0 ]; then
    PS1='# '
    else
    PS1='$ '
    fi
    fi
    fi

    export PATH
    umask 022

    #================================================= ===
    # root as login ~/.bashrc

    # ~/.bashrc: executed by bash(1) for non-login shells.

    export PS1='\h:\w\$ '
    umask 022

    # You may uncomment the following lines if you want `ls' to be colorized:
    # export LS_OPTIONS='--color=auto'
    # eval "`dircolors`"
    # alias ls='ls $LS_OPTIONS'
    # alias ll='ls $LS_OPTIONS -l'
    # alias l='ls $LS_OPTIONS -lA'
    #
    # Some more alias to avoid making mistakes:
    # alias rm='rm -i'
    # alias cp='cp -i'
    # alias mv='mv -i'

    # ------------------------------------------
    # response at terminal logged in as root

    ics-debian401-hda3:~# $PATH
    bash: /usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11:/usr/games: No such file or directory
    ics-debian401-hda3:~# su -
    ics-debian401-hda3:~# $PATH
    -su: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/jdk1.6.0_01/bin: No such file or directory
    ics-debian401-hda3:~# echo $PS1
    \h:\w\$
    ics-debian401-hda3:~#

    # --------------------------------------------
    # ~/.profile: executed by Bourne-compatible login shells.

    if [ -f ~/.bashrc ]; then
    . ~/.bashrc
    fi

    mesg n
    # ---------------------------------------------
    # There is no root login ~/.bash_profile
    # ---------------------------------------------
    /*

    From this the super user is getting a path from the /etc/profile, but root is getting a path from somewhere else as it does not even compare with the signature from the else part of the /etc/profile

    */
    #logged in as keith
    # =======================================
    # ~/.bash_profile: executed by bash(1) for login shells.
    # see /usr/share/doc/bash/examples/startup-files for examples.
    # the files are located in the bash-doc package.

    # the default umask is set in /etc/login.defs
    #umask 022

    # include .bashrc if it exists
    if [ -f ~/.bashrc ]; then
    . ~/.bashrc
    fi

    # set PATH so it includes user's private bin if it exists
    if [ -d ~/bin ] ; then
    PATH=~/bin:"${PATH}"
    fi

    # -----------------------------------
    # ~/.bashrc: executed by bash(1) for non-login shells.
    # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
    # for examples

    # If not running interactively, don't do anything
    [ -z "$PS1" ] && return

    # don't put duplicate lines in the history. See bash(1) for more options
    export HISTCONTROL=ignoredups

    # check the window size after each command and, if necessary,
    # update the values of LINES and COLUMNS.
    shopt -s checkwinsize

    # make less more friendly for non-text input files, see lesspipe(1)
    [ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"

    # set variable identifying the chroot you work in (used in the prompt below)
    if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
    fi

    # set a fancy prompt (non-color, unless we know we "want" color)
    case "$TERM" in
    xterm-color)
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    ;;
    *)
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    ;;
    esac

    # Comment in the above and uncomment this below for a color prompt
    #PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

    # If this is an xterm set the title to user@host:dir
    case "$TERM" in
    xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
    ;;
    *)
    ;;
    esac

    # Alias definitions.
    # You may want to put all your additions into a separate file like
    # ~/.bash_aliases, instead of adding them here directly.
    # See /usr/share/doc/bash-doc/examples in the bash-doc package.

    #if [ -f ~/.bash_aliases ]; then
    # . ~/.bash_aliases
    #fi

    # enable color support of ls and also add handy aliases
    if [ "$TERM" != "dumb" ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=auto'
    #alias dir='ls --color=auto --format=vertical'
    #alias vdir='ls --color=auto --format=long'
    fi

    # some more ls aliases
    #alias ll='ls -l'
    #alias la='ls -A'
    #alias l='ls -CF'

    # enable programmable completion features (you don't need to enable
    # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
    # sources /etc/bash.bashrc).
    if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
    fi
    #----------------------------------------------------
    response at terminal logged in as keith

    keith@ics-debian401-hda3:~$ echo $PATH
    /usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
    keith@ics-debian401-hda3:~$ su -
    Password:
    ics-debian401-hda3:~# echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/jdk1.6.0_01/bin
    ics-debian401-hda3:~#

    /*
    Again similar response to root login, the $PATH signature does not appear to match any known export PATH statement

    */
    #+++++++++++++++++++++++++++++++

    Many thanks

    Regards

    Keith

  5. #5
    Just Joined! tuxv's Avatar
    Join Date
    Jul 2006
    Location
    Colombo, Sri Lanka
    Posts
    92
    Found it

    I finally found out how to do it, I removed and installed java to a different location, /usr/jdk1.6.0_01

    then I use this simple procedure to set the PATH
    Code:
    sudo nano .etc.profile
    and made it to llok like this
    # /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
    # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

    if [ "`id -u`" -eq 0 ]; then
    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    else
    PATH="/usr/local/bin:/usr/bin:/bin:/usr/games"
    fi

    if [ "$PS1" ]; then
    if [ "$BASH" ]; then
    PS1='\u@\h:\w\$ '
    else
    if [ "`id -u`" -eq 0 ]; then
    PS1='# '
    else
    PS1='$ '
    fi
    fi
    fi

    export PATH

    JAVA_HOME="/usr/jdk1.6.0_01"
    export JAVA_HOME

    PATH="/usr/jdk1.6.0_01/bin:$PATH"
    export PATH

    umask 022
    note these changes in this file
    Code:
    JAVA_HOME="/usr/jdk1.6.0_01"
    export JAVA_HOME
    
    PATH="/usr/jdk1.6.0_01/bin:$PATH"
    export PATH
    cheers

  6. #6
    Just Joined!
    Join Date
    Apr 2007
    Posts
    3

    Cool

    Dear tuxv

    You have solved a problem I do not have. My problem is the path for login users.

    I seek the source of the PATH for login users

    It contains an X11 path , and it is not set by /etc/profile as my previous post shows

    I live in hope

    Regards

    Keith

  7. #7
    Just Joined!
    Join Date
    Apr 2008
    Posts
    1
    Hello everyone,

    I believe I have found why the path is not updated from the profile. This is especially true if you are running gnome desktop. There are 2 approaches to fix this.

    Approach 1:

    Open the configuration editior (Applications -> System Tools -> Configuration Editor)

    Then open the gnome-terminal profiles in the configuration editor.
    apps -> gnome-terminal -> profiles -> Default
    look for the login_shell and make the check the option. This forces the loading of the profile just as it was a login session and reads the /etc/profile

    The Second option involves editing /etc/login.defs and look for the following
    ENV_SUPATH PATH=/usr/local/bin...
    ENV_PATH PATH=/usr/local/bin...
    and edit the path to meet your needs

    Option one is the better one as it is not as intrusive to files that may be overwritten.

    Cheers,
    Max

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •