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 11 set path at login ?

If none of the specific sub-forums seem right for your thread, ask here.
Message
Author
gh4rock
Posts: 13
Joined: 2021-08-29 13:10

Debian 11 set path at login ?

#1 Post by gh4rock »

I would like to have my user $PATH expanded once at login to include $HOME/bin.
The following 2 commands do this:
PATH=$PATH:$HOME/bin
export PATH

On some versions of Linux, these 2 commands can be added to a .bash_profile file in the users $HOME directory.
This file would be executed once at login.
Debian 11 does not appear to use this feature.
So what can the user do to have these 2 commands executed automatically (once) at login ?

User avatar
ticojohn
Posts: 1284
Joined: 2009-08-29 18:10
Location: Costa Rica
Has thanked: 21 times
Been thanked: 44 times

Re: Debian 11 set path at login ?

#2 Post by ticojohn »

I use Debian 11, AMD64, XFCE. Looking at /home/user/.profile I see the following:

Code: Select all

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# 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/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# 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:$PATH"
fi
As the comment says, the file is NOT read by bash(1) if ~/.bash_profile or ~/.bash_login exists. Take a look in your /home directory. I would think that this file is there. PATH $HOME/bin should be set..
I am not irrational, I'm just quantum probabilistic.

gh4rock
Posts: 13
Joined: 2021-08-29 13:10

Re: Debian 11 set path at login ?

#3 Post by gh4rock »

Thanks for the idea to check .profile. My .profile is the default version for Debian 11.
No matter what I do, the path is always:
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

If I execute .profile from the command line, then it changes to
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/bright/bin

I changed the .profile so that $HOME/bin appends to the end of the path
So that I know .profile is being executed.

That tells me that the login shell is NOT executing .profile at login.
Last edited by gh4rock on 2021-08-29 18:51, edited 1 time in total.

mm3100
Posts: 336
Joined: 2020-10-21 21:39
Has thanked: 8 times
Been thanked: 13 times

Re: Debian 11 set path at login ?

#4 Post by mm3100 »

ticojohn wrote: 2021-08-29 13:54 As the comment says, the file is NOT read by bash(1) if ~/.bash_profile or ~/.bash_login exists. Take a look in your /home directory. I would think that this file is there. PATH $HOME/bin should be set..
Did you check those?

gh4rock
Posts: 13
Joined: 2021-08-29 13:10

Re: Debian 11 set path at login ?

#5 Post by gh4rock »

Removed .bash_profile, no .bash_login file.
I will try a smaller .profile without .bashrc to see if that has any affect.

mm3100
Posts: 336
Joined: 2020-10-21 21:39
Has thanked: 8 times
Been thanked: 13 times

Re: Debian 11 set path at login ?

#6 Post by mm3100 »

Mate, if you had .bash_profile, then .profile wasn't being read by bash. No need to remove .bashrc, or change .profile. Just read what is commented in .profile as ticojohn commented.

gh4rock
Posts: 13
Joined: 2021-08-29 13:10

Re: Debian 11 set path at login ?

#7 Post by gh4rock »

I am using Debian 11, Cinnamon desktop.
No .bash_profile.
Tried shorter .profile with only the segment with $HOME/bin.
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
if I execute .profile from the command line, then the $HOME/bin
gets added, otherwise, it does not get added ???

User avatar
ticojohn
Posts: 1284
Joined: 2009-08-29 18:10
Location: Costa Rica
Has thanked: 21 times
Been thanked: 44 times

Re: Debian 11 set path at login ?

#8 Post by ticojohn »

gh4rock wrote: 2021-08-29 20:18 I am using Debian 11, Cinnamon desktop.
No .bash_profile.
Tried shorter .profile with only the segment with $HOME/bin.
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
if I execute .profile from the command line, then the $HOME/bin
gets added, otherwise, it does not get added ???
Okay. I created a $HOME/bin directory, logged out and back in. It is still not in the PATH. So I added this to the end of the .bashrc file

Code: Select all

PATH="$HOME/bin:$PATH"
and it now shows in the PATH. Not sure why it doesn't work from .profile but now you should have a solution.

EDIT: And this interesting. In ~/.profile there is a line that says:

Code: Select all

# see /usr/share/doc/bash/examples/startup-files for examples.
I am unable to find /usr/share/doc/bash/examples/startup-files. Is it just me?
I am not irrational, I'm just quantum probabilistic.

User avatar
ticojohn
Posts: 1284
Joined: 2009-08-29 18:10
Location: Costa Rica
Has thanked: 21 times
Been thanked: 44 times

Re: Debian 11 set path at login ?

#9 Post by ticojohn »

I believe that there may be a problem with ~/.profile and the inclusion of $HOME/bin in PATH. I made a temporary change to ~/.profile by adding an echo statement in

Code: Select all

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ]; then
    PATH="$HOME/bin:$PATH"
    echo 1
fi
When I execute ~/.profile and then check the PATH I get this

Code: Select all

john@debian:~$ bash ~/.profile
1
john@debian:~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
We can clearly see that the if statement is being executed. And I have a bin folder in $HOME, so why isn't $HOME/bin getting added to PATH? Am I misunderstanding what should be happening? I hope my efforts aren't construed as hijacking this thread. I am just trying to help the OP to figure what is happening and why $HOME/bin isn't getting added as per ~/.profile.
I am not irrational, I'm just quantum probabilistic.

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: Debian 11 set path at login ?

#10 Post by Dai_trying »

You could try the following which works on my system

Code: Select all

. ~/.profile
I usually copy the code you showed

Code: Select all

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ]; then
    PATH="$HOME/bin:$PATH"
    echo 1
fi
to my ~/.bashrc file to ensure all terminals have access to my scripts.

User avatar
Bloom
df -h | grep > 90TiB
df -h | grep > 90TiB
Posts: 503
Joined: 2017-11-11 12:23
Been thanked: 26 times

Re: Debian 11 set path at login ?

#11 Post by Bloom »

You forgot the export:

Code: Select all

export PATH="$HOME/bin:$PATH"

User avatar
ticojohn
Posts: 1284
Joined: 2009-08-29 18:10
Location: Costa Rica
Has thanked: 21 times
Been thanked: 44 times

Re: Debian 11 set path at login ?

#12 Post by ticojohn »

Bloom wrote: 2021-08-30 11:24 You forgot the export:

Code: Select all

export PATH="$HOME/bin:$PATH"
Interesting! I was just reporting exactly what is in ~/.profile as it was apparently generated by the system when a user is created. Does that imply that the system didn't create the correct code? Weird. But I'll take a look. Hopefully the OP sees all this.

Okay. I modified ~/.profile as suggested by @Bloom . Still no joy. I also tried the following, which also didn't work.

Code: Select all

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ]; then
    PATH="$HOME/bin:$PATH"
    export $PATH
fi
I am at a loss. As for me, it is not important. Just trying to find a solution for the OP. The one thing I found that DOES work, is putting

Code: Select all

    PATH="$HOME/bin:$PATH"
 
at the end of the ~/.bashrc file.
I am not irrational, I'm just quantum probabilistic.

gh4rock
Posts: 13
Joined: 2021-08-29 13:10

Re: Debian 11 set path at login ?

#13 Post by gh4rock »

Thanks all for confirming that there is a problem.
To see the bash examples, one must add the bash-doc pkg.

I did some more testing and determined that .bash-login file does append the $HOME/bin to the PATH.
But the results of the "export PATH" do not survive the login sequence, and one is left with the
default path provided by /etc/profile.

Removing .bash_profile and .bash_login so as to work only with .profile has the same result.
Executing .profile from the command line does work, does change the PATH to include $HOME/bin.
But it does NOT appear to be executed during the normal login process.

This means that one must execute a simple script to change the PATH after login.
Trying to run the script automatically via settings... "Startup" does not work either.

User avatar
ticojohn
Posts: 1284
Joined: 2009-08-29 18:10
Location: Costa Rica
Has thanked: 21 times
Been thanked: 44 times

Re: Debian 11 set path at login ?

#14 Post by ticojohn »

gh4rock wrote: 2021-08-30 13:32 Thanks all for confirming that there is a problem.
To see the bash examples, one must add the bash-doc pkg.

I did some more testing and determined that .bash-login file does append the $HOME/bin to the PATH.
But the results of the "export PATH" do not survive the login sequence, and one is left with the
default path provided by /etc/profile.

Removing .bash_profile and .bash_login so as to work only with .profile has the same result.
Executing .profile from the command line does work, does change the PATH to include $HOME/bin.
But it does NOT appear to be executed during the normal login process.

This means that one must execute a simple script to change the PATH after login.
Trying to run the script automatically via settings... "Startup" does not work either.
The only way I've gotten it to work is to add

Code: Select all

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ]; then
   PATH="$HOME/bin:$PATH"
fi
to the end of the ~/.bashrc file.
I am not irrational, I'm just quantum probabilistic.

gh4rock
Posts: 13
Joined: 2021-08-29 13:10

Re: Debian 11 set path at login ?

#15 Post by gh4rock »

I reached the same conclusion !!!
But added "export PATH" after the if...fi lines.
Thanks for the help !!!

User avatar
ticojohn
Posts: 1284
Joined: 2009-08-29 18:10
Location: Costa Rica
Has thanked: 21 times
Been thanked: 44 times

Re: Debian 11 set path at login ?

#16 Post by ticojohn »

gh4rock wrote: 2021-08-30 13:52 I reached the same conclusion !!!
But added "export PATH" after the if...fi lines.
Thanks for the help !!!
That's cool. I found that it worked without adding export PATH. But if it works for you then go with it. But it would be nice to find out why the code in ~/.profile doesn't work as one would think it should. But then again I am NOT an expert, so maybe what I think I understand is totally wrong. Wouldn't be the first, or last, time. :lol:
I am not irrational, I'm just quantum probabilistic.

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: Debian 11 set path at login ?

#17 Post by Dai_trying »

It could be that you have a (global settings) bash.bashrc file in /etc/ that gets called and therefore prevents the .profile in ~/ being called, I haven't looked into this recently but am going from memory when I wanted my ~/bin/ added to $PATH.

User avatar
ticojohn
Posts: 1284
Joined: 2009-08-29 18:10
Location: Costa Rica
Has thanked: 21 times
Been thanked: 44 times

Re: Debian 11 set path at login ?

#18 Post by ticojohn »

Dai_trying wrote: 2021-08-30 17:26 It could be that you have a (global settings) bash.bashrc file in /etc/ that gets called and therefore prevents the .profile in ~/ being called, I haven't looked into this recently but am going from memory when I wanted my ~/bin/ added to $PATH.
Well, there is certainly a /etc/bash.bashrc file. I certainly don't have the indepth system knowledge to understand why that would prevent ~/.profile from being called. From everything I have read, and misunderstood, ~/.profile is supposed to be called because it has specifics for the user. But then again, as VM Smith said, I am but an egg!
I am not irrational, I'm just quantum probabilistic.

User avatar
ticojohn
Posts: 1284
Joined: 2009-08-29 18:10
Location: Costa Rica
Has thanked: 21 times
Been thanked: 44 times

Re: Debian 11 set path at login ?

#19 Post by ticojohn »

Okay. Doing some research and I HOPE I got this correct. From what I read , ~/.profile gets executed when you log in via an interactive login shell but not when you log in to a graphical environment. Hence, one needs to put the code to add the $HOME/bin path at the end of $HOME/.bashrc if you want that path added automatically at log in.

It would be nice if an expert could confirm my conclusion.
I am not irrational, I'm just quantum probabilistic.

User avatar
craigevil
Posts: 5391
Joined: 2006-09-17 03:17
Location: heaven
Has thanked: 28 times
Been thanked: 39 times

Re: Debian 11 set path at login ?

#20 Post by craigevil »

This is what I get:

Code: Select all

echo $PATH
/home/pi/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/lib/surfraw:/usr/lib/surfraw:/usr/lib/surfraw:/usr/lib/surfraw
I took the info from .profile and added it to my .bashrc

Code: Select all

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

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi
Then I ran

Code: Select all

source ~/.bashrc
All is good.

Edit:
Nope closing the terminal and opening a new one doesn't show it until I add:
PATH="$HOME/bin:$PATH"
to my ~.bashrc
Last edited by craigevil on 2021-08-30 19:41, edited 2 times in total.
Raspberry PI 400 Distro: Raspberry Pi OS Base: Debian Sid Kernel: 5.15.69-v8+ aarch64 DE: MATE Ram 4GB
Debian - "If you can't apt install something, it isn't useful or doesn't exist"
My Giant Sources.list

Post Reply