24

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?

David Doria
  • 344
  • 1
  • 2
  • 10

3 Answers3

31

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
Rich Homolka
  • 31,057
  • 6
  • 55
  • 80
  • 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? – David Doria Feb 03 '12 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 – Rich Homolka Feb 03 '12 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 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=636108 – jhenninger Feb 03 '12 at 23:30
  • I am using KDM. – David Doria Feb 04 '12 at 02: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 Sep 12 '13 at 03:00
  • ~/.bashrc is the place instead of ~/.profile add your data to ~/.bashrc for terminal to pick up in non-login mode. Hope it helps. – Doogle Aug 25 '18 at 16:35
5

try using ~/.bashrc instead.

goweon
  • 1,693
  • 2
  • 19
  • 21
2

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:

fvue
  • 123
  • 3
  • 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 Feb 04 '13 at 01: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 Feb 04 '13 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](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=636108). – Alois Mahdal Oct 27 '14 at 08: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 Sep 08 '18 at 12:22