26

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?

0

3 Answers 3

32

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
6
  • 1
    So 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
    – jhenninger
    Commented Feb 3, 2012 at 23:30
  • I am using KDM. Commented Feb 4, 2012 at 2:25
  • 3
    If 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.
    – Lambart
    Commented Sep 12, 2013 at 3:00
5

try using ~/.bashrc instead.

3

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:

4
  • 1
    This explains how to get your .profile sourced at login, but he's actually wondering about how to get bash to source it when he launches a terminal (not at login)
    – cpast
    Commented 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.
    – fvue
    Commented 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.
    – RichieHH
    Commented Sep 8, 2018 at 12:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .