When installing RVM the one gets the following message:
* WARNING: You have '~/.profile' file, you might want to load it,
to do that add the following line to '/home/dotancohen/.bash_profile':
source ~/.profile
I'm concerned because my ~/.profile file contains xmodmap ~/.Xmodmap
which I obviously don't want to run (swapping my CapsLock and ESC keys) every time I open a new shell.
Why might the wise RVM devs suggest sourcing .profile
in .bash_profile
?
Best Answer
.profile
and.bash_profile
are identical in terms of when they're meant to be executed: they're executed when you log in. The difference is that only bash runs.bash_profile
; Bourne-style shells (dash, ksh, etc.) runs.profile
. Bash itself runs.profile
if.bash_profile
doesn't exist.Even if you have bash as your login shell,
.profile
is often the one that's executed when you log in in graphical mode — many distributions set up the X session startup script to run undersh
and load.profile
.Hence the advice to use
.profile
instead of.bash_profile
to do things like defining environment variables. Unless you absolutely need bash-specific features, just put everything in.profile
. But even if you do, there's a reason to keep a.bash_profile
, which is that when bash loads it, it doesn't load.bashrc
, even if it's interactive. Hence, for most people,~/.bash_profile
should consist of these two lines:You should not run
xmodmap
from.profile
. This isn't executed when you open a new shell, but it is executed, for example, when you log in remotely with SSH with X11 forwarding. Unfortunately, there's no standard file that's loaded when you log in in graphical mode. Debian loads~/.xsessionrc
(I think this applies to all display managers, except Gdm which loads~/.xprofile
instead); other distributions have different setups. If you need cross-distribution portability, it may be easier to configure your desktop environment to executexmodmap
when it starts. If all you're doing is swapping CapsLock and Ctrl, this can be done with XKB settings that most modern desktop environments provide an interface to.