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?

  • Why don't you want it to run every time you open a new shell? – David King Jan 6 '16 at 14:58
  • @DavidKing: Because then my CapsLock and ESC keys will swap their functions between them each time a bash session is started. Xmodmap affects the X session, not the terminal session. – dotancohen Jan 6 '16 at 15:38
  • 1
    i guess the rvm guys don't know how shell profiles are supposed to work. they've got it ass-backwards. (but so does bash generally, too). ~/.profile:/etc/profile is sourced at login by login shells (provided they are not profile shells - which have different profiles) and environment files (.rcs) are sourced by any new interactive shell (though its supposed to be done for the value of $ENV, really). you've got it right, though. nevermind, that. – mikeserv Jan 6 '16 at 15:53

.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 under sh 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:

. ~/.profile
case  $- in *i*) . ~/.bashrc;; esac

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 execute xmodmap 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.

  • Thank you. It seems that Ubuntu 15.10 (with Unity) does not run even ~/.xsessionrc on graphical login. That's just for your information, according to the fine intercords, there doesn't seem to be any file that is loaded on graphical login. – dotancohen Jan 7 '16 at 13:32
  • @dotancohen Funny, I do see the loading of .xsessionrc in the scripts even on Ubuntu 15.10. Oh, looks like this bug. With gdm, you need to use ~/.xprofile. – Gilles 'SO- stop being evil' Jan 7 '16 at 15:50

Remember that bash(1) is the only shell that reads .bash_profile, other Bourne shell derivatives just read .profile. If you sometimes use another shell, you'd want to keep .profile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.