When I start a bash terminal, my .profile is not being executed. I do not have a ~/.bash_profile or a ~/.bash_login, so .profile is supposed to run, right? What else could be wrong?
3 Answers
It's not a login shell.
If a shell is a login shell, it will look for .bash_profile if it exists, then .profile. Other shells look for .bashrc
So, you can put the things you want in every shell instance in .bashrc, and possibly have a reference that sources .bashrc in .profile.
So: .bashrc:
stuff you want
end of .profile:
[ -n "$BASH" ] && [ -f ~/.bashrc ] && . ~/.bashrc
-
1So when I run 'konsole' in KDE, that is a non-login shell, right? On another machine I have definitely put things in .profile and had them work when I open a terminal like this - I guess I don't understand when you'd want something different to happen at login vs when you open a terminal? Commented Feb 3, 2012 at 22:53
-
@DavidDoria it depends, I have changed configs or made aliases to what konsole runs, to make it run
bash --login
. In your case it seems to just run bash, which by default will not trigger a login shell Commented Feb 3, 2012 at 22:56 -
If you are using LightDM that might be the reason. Other display managers like GDM and KDM source .profile on login, but LightDM does not (by design). See bugs.debian.org/cgi-bin/bugreport.cgi?bug=636108 Commented Feb 3, 2012 at 23:30
-
-
3If you are using Gnome Terminal, you can do Edit->Profile Preferences, go to the Title and Command tab, and check "Run command as a login shell". It will then source your .bash_profile or .profile whenever you open a terminal, as expected.– LambartCommented Sep 12, 2013 at 3:00
If you're using a graphical desktop, .profile should be sourced by your desktop manager. Lightdm does source .profile now, at least on Ubuntu. See: https://bugs.launchpad.net/ubuntu/+source/lightdm/+bug/794315
With kdm, and Kubuntu-12.04, the file /etc/kde4/kdm/Xsession gets sourced, which does the .profile including. Kubuntu-12.10 will probably use lightdm. Ubuntu 12.04 uses lightdm so that /usr/sbin/lightdm-session sources .profile.
I think the way to go is to (1) set/export environment settings in ~/.profile and (2) have .profile sourced by .bash_profile:
[[ -f ~/.profile ]] && . ~/.profile
(and not have .bashrc sourced by either .profile or .bash_profile).
See also:
- Setting the BROWSER environment variable in .profile: http://fvue.nl/wiki/Linux:_Default_browser
-
1This explains how to get your
.profile
sourced at login, but he's actually wondering about how to getbash
to source it when he launches a terminal (not at login)– cpastCommented Feb 4, 2013 at 1:07 -
You shouldn't want to have .profile sourced when you launch a new terminal (from within KDE). The whole purpose of .profile is to have it sourced once at login, either on a graphical terminal or a text terminal; .profile should've been sourced the moment you logged into KDE.– fvueCommented Feb 4, 2013 at 11:32
-
.profile should be sourced by your desktop manager. Well this depends on understanding of the file's purpose. In Debian, /etc/profile (and ~/.profile as its extension) is meant to be for bash-like shells. Commented Oct 27, 2014 at 8:24
-
You don't need to source it again IF its sourced at login. your bash will inherit it unless you're doing something silly like "export PATH=~/.bin" or something causing it to be overwritten.– RichieHHCommented Sep 8, 2018 at 12:22