Well, about "Graphical Logins", it depends on which *DM you use ...
With GDM (Gnome 3.18) I have this:
/etc/gdm/Xsession
#!/bin/sh <= *important*
...
# First read /etc/profile and .profile
test -f /etc/profile && . /etc/profile
test -f "$HOME/.profile" && . "$HOME/.profile"
# Second read /etc/xprofile and .xprofile for X specific setup
test -f /etc/xprofile && . /etc/xprofile
test -f "$HOME/.xprofile" && . "$HOME/.xprofile"
So, ~/.profile gets sourced in login using /bin/sh and not /bin/bash
There are two cases
- /bin/sh is linked to /bin/bash but runs in "POSIX/Bourne" mode
- /bin/sh is /bin/dash (debian/ubuntu). Fastest but with less features (ShellShock support ;) )
So the /bin/sh profile is ~/.profile and not ~/.bash_profile, ~/.zprofile
This file should be used for "shell agnostic" settings, like path and environment variables.
NO executable program for login-only user interaction should be but here
(mail check, fortune, etc ...)
the ~/.*rc are meant only for "interactive" sessions (aliases for instance ...)
There is a difference among bash and zsh for interactive login shells
bash sources only .bash_profile, while zsh sources in the order:
- ~/.zprofile
- ~/.zshrc
- ~/zlogin (here aliases defined in ~/.zshrc are available. in case of "interactive" + "login" shells
The right way to do ~/.bash_profile was answered here:
Difference between .bashrc and .bash_profile
if [ -r ~/.profile ]; then . ~/.profile; fi
case "$-" in *i*) if [ -r ~/.bashrc ]; then . ~/.bashrc; fi;; esac
To enable test (and profiling), you may use this
~/.bash_profile:
#!/bin/bash
# ------------------------------------------------
export _DOT_BASH_PROFILE_0=`date --rfc-3339=ns`
# ------------------------------------------------
if [ -f ~/.profile ] ; then
. ~/.profile
fi
case "$-" in *i*) if [ -r ~/.bashrc ]; then . ~/.bashrc; fi;; esac
# ------------------------------------------------
export _DOT_BASH_PROFILE_1=`date --rfc-3339=ns`
# ------------------------------------------------
~/.zprofile:
#!/bin/zsh
# ------------------------------------------------
export _DOT_ZSH_PROFILE_0=`date --rfc-3339=ns`
# ------------------------------------------------
if [ -f ~/.profile ] ; then
. ~/.profile
fi
# no need to source, zsh already handle ~/.zshrc
###case "$-" in *i*) if [ -r ~/.zshrc ]; then . ~/.zshrc; fi;; esac
# ------------------------------------------------
export _DOT_ZSH_PROFILE_1=`date --rfc-3339=ns`
# ------------------------------------------------
then, to test:
chsh -s /bin/bash
ssh localhost
env
exit
ssh localhost env
ssh -t localhost bash -i -c env
chsh -s /bin/zsh
ssh localhost
env
exit
ssh localhost env
ssh -t localhost bash -i -c env
So RVM/virtualenv should go in ~/.profile, IMHO
But this DOES NOT WORK, sometimes ...
For instance, virualenvwrapper works only if the shell
running Xsession is an "original" bash (exporting BASH_VERSION)
If you are on a dash system, the environment variable and path setting work, but virualenvwrapper function definition do not work because the script is not POSIX compliant.
The script doesn't give any error but it ends without any "workon" definition.
So you can set the environment at hand in ~/.profile, just to enable the correct python execution from client started directly from X:
export VIRTUAL_ENV="/home/mike/var/virtualenvs/myvirtualenv"
export PATH="$VIRTUAL_ENV/bin:$PATH"
unset PYTHON_HOME
https://gist.github.com/datagrok/2199506
https://www.bountysource.com/issues/9061991-setting-up-your-computer-virtualenvwrapper-linux-all
But for virualenvwrapper you have two alternatives:
- source it in ~/.bash_profile or ~/.zprofile (or ~/.zlogin) when terminal acts as login shell
- include the script in ~/.bashrc or ~/zshrc
This means that X clients (emacs for instance) should be started from the terminal shell and not from the graphical one!
"I can't get no satisfaction ..."
1I think I understand, I might have to read it more times to internalize it more but I am concluding the following. In enterprise environments in order to have finer control of the customized shells without side effects of the global one it is best practice to put environment variables in ~/.bash_profile. In a personal environment like Ubuntu or Linux Mint in order to have the PATH properly set I should set it under ~/.bashrc (or even in /etc/profile). Am I correct? – Viriato – 2012-04-06T05:00:29.293
It has less to do with enterprise environments than with whether you are just a user or a developer; the systems like
modules
andrvm
are developer tools, as are Matlab and Cadence for somewhat different definitions of "developer". Simple development also doesn't require them, but when you need to test against multiple versions of Ruby, Perl, or Python then you really want something likervm
,perlbrew
, andvirtualenv
(respectively) around to help keep it all straight. – geekosaur – 2012-04-06T05:22:13.443