Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Debian default $PATH where it comes from?

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
pedegie
Posts: 4
Joined: 2018-10-06 20:29

Debian default $PATH where it comes from?

#1 Post by pedegie »

Hello I'm curious where the default $PATH variable comes from which contains /games/ among others. I was trying to remove it but unsuccessfully. I found that PATH is set in:
/etc/login.defs
/etc/profile
/etc/environment
some .bashrc, .bash_profile, .config files

I removed entry from each file, then reset PC but it still shows `/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games` on echo $PATH.
I know I can just override it but I'm really curious where it comes from.

EDIT: I'm using 4.9.0-8-amd64 #1 SMP Debian 4.9.110-3+deb9u5 (2018-09-30) x86_64 GNU/Linux

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Debian default $PATH where it comes from?

#2 Post by Head_on_a_Stick »

PATH is set in ~/.profile

~/.profile is copied from /etc/skel/.profile (provided by the bash package) by the adduser(8) program when a new user is created.

EDIT: note though that bash will not read ~/.profile if ~/.bash_profile exists.
deadbang

pedegie
Posts: 4
Joined: 2018-10-06 20:29

Re: Debian default $PATH where it comes from?

#3 Post by pedegie »

.profile

Code: Select all

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:/bin"
fi
Yep but I removed also from there

I found

Code: Select all

dbus-update-activation-environment: setting PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
in .xsession-errors. Maybe its related in some way?

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Debian default $PATH where it comes from?

#4 Post by Head_on_a_Stick »

Debian seems to be setting PATH originally via the sysprofile package and a convoluted series of abstractions which I can't follow atm :?

Luckily for us this all irrelevant because if you have a specific PATH that you wish to set for any given user then simply override the default in ~/.profile, like this:

Code: Select all

export PATH="${HOME}/bin:/usr/local/bin:/usr/bin:/bin"
^ So that would remove /usr{,/local}/games from that user's PATH and add ~/bin ;)

EDIT: your modification of ~/.profile did not work because in that stanza PATH is only set if ~/bin exists and I presume that it does not exist for your user.

My line would set PATH even if ~/bin does not exist (although it would be silly to add ${HOME}/bin to PATH in that case, obviously).
deadbang

pedegie
Posts: 4
Joined: 2018-10-06 20:29

Re: Debian default $PATH where it comes from?

#5 Post by pedegie »

Alright I put export PATH to .profile, thanks for clarifying and your help :)

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Debian default $PATH where it comes from?

#6 Post by Head_on_a_Stick »

You're welcome :)

Please add [SOLVED] to the thread title to help others with this problem — it may also be best to change the title to "Debian: setting PATH for user" because I didn't actually find out how the default PATH is set.
deadbang

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: Debian default $PATH where it comes from?

#7 Post by debiman »

pedegie wrote:.profile

Code: Select all

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:/bin"
fi
this is wrong.
where did you get that from?
it should be something like PATH="$HOME/bin:$PATH"

also look at /etc/profile.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Debian default $PATH where it comes from?

#8 Post by Head_on_a_Stick »

debiman wrote:
pedegie wrote:.profile

Code: Select all

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:/bin"
fi
this is wrong.
where did you get that from?
That was the OP's attempted modification to that file.

It had no effect because ~/bin does not exist for that user ;)
deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Debian default $PATH where it comes from?

#9 Post by Head_on_a_Stick »

debiman wrote:look at /etc/profile.
Did you even bother to look in /etc/profile yourself before posting?

I ask because I did check and there is no mention of PATH in that file at all...
deadbang

pedegie
Posts: 4
Joined: 2018-10-06 20:29

Re: Debian default $PATH where it comes from?

#10 Post by pedegie »

Yep I have this there (which i also modified before posting):

Code: Select all

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/bin:/bin"
fi
export PATH
Head_on_a_stick: How can I change topic's name? I want add that it's solved

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Debian default $PATH where it comes from?

#11 Post by Head_on_a_Stick »

pedegie wrote:How can I change topic's name? I want add that it's solved
Edit the first post in this thread, that contains the "title" section for the thread and this is where you need to add [SOLVED].
deadbang

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: Debian default $PATH where it comes from?

#12 Post by debiman »

Head_on_a_Stick wrote:
debiman wrote:look at /etc/profile.
Did you even bother to look in /etc/profile yourself before posting?

I ask because I did check and there is no mention of PATH in that file at all...
i did, and there is.
on my debian system, it is the literal answer to the OP's title.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Debian default $PATH where it comes from?

#13 Post by Head_on_a_Stick »

^ Really? :o

In which case, sorry about that, my mistake.
deadbang

Post Reply