Bash not sourcing .profile automatically in Debian 11
So, in order to avoid typing "flatpak run", every time I need to run a flatpak program from the terminal, to have gui programs installed using nix appear in my applications menu(rofi, in this case), and to avoid typing the entire path to my .local/bin, I had added the following lines to my .profile:
set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
export PATH="$HOME/bin:$PATH"
fi
set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
export PATH="$HOME/.local/bin:$PATH"
fi
for desktop entries for packages installed using Nix
.profileis only sourced when the shell is a login shell. Most shells started by terminal emulators under a GUI are not login shells.
Depending on how you connect to a machine, you may or may not get a login shell. Through SSH or similar may well get you a login shell. Using the text-console (usually through Ctrl+Alt+F1 through F6 on modern distros) also yields a login shell.
Try putting things in your .bashrc instead. That one is sourced regardless of login shell or not.
If you're not using bash, substitute the relevant file. .zshrc and .config/fish are the main two.
Thanks, that works with the flatpaks.
However, it doesn't seem to work with nix packages.
I mean rofi doesn't detect the .desktop files for packages installed using nix.
Do you have anything else your ~/.bashrc that is perhaps overwriting the PATH?
One thing you can do is just add echos to your .profile to see if it is getting sourced and what the state of PATH is as it gets loaded. That might help you trace what is happening.
Does your .bashrc actually source .bash_profile? Add [ ! -f "~/.bash_profile" ] || . "~/.bash_profile" (.bash_profile doesn't exist or source it) to the end if not.
You've probably already checked it out but make sure you've got only one of .profile, .bash_profile, .bashprofile. bash will only execute one of them in case there's more than one (not sure which one off the top of my head.)
But those kinds of initialisations belong in .profile (or, if you're using a weird desktop environment, its own configuration file), particularly if you want .desktop files to work. (In .bashrc, PATH will grow longer in each subshell, which shouldn't cause problems but is wasteful.)
So, what desktop environment (GNOME, KDE, Cinnamon, etc.) are you using?
.profile is executed by login shells for the benefit of it and its subshells, and by DEs like Cinnamon for the benefit of .desktop launchers at login.
So, have you logged out and back in again since adding these lines to .profile?
And of course, the .profile has to be executed properly for its configuration to take effect, so it`s useful to know if the problem is with those specific lines, or the file as a whole.
Add:—
date >> ~/profile-execution-log-top.txt
echo $PATH >> ~/profile-execution-log-top.txt
to the top of .profile, and:—
date >> ~/profile-execution-log-end.txt
echo $PATH >> ~/profile-execution-log-end.txt
to the bottom of .profile (use alternative paths as you see fit) to monitor that activity. You can test this by sourcing .profile but the real test is logging out and in again. Look at the time when you do this so you can correlate each action with each timestamp in the log files. If .profile is executed to completion, you should have two files with matching timestamps but different PATHs. If you don't have a matching timestamp in the "end" log file, there's a problem mid-execution. If neither file is being updated, .profile isn't being executed at all.