Why do I need to run "/bin/bash --login"
Solution 1:
It sounds like the environment necessary for the system to find the installed ruby components is specified in a file that only gets read for login shells. The bash manual page has this to say about the difference between login shells and non-login shells:
INVOCATION
A login shell is one whose first character of argument zero is a -, or
one started with the --login option.
and
When bash is invoked as an interactive login shell, or as a non-inter‐
active shell with the --login option, it first reads and executes com‐
mands from the file /etc/profile, if that file exists. After reading
that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
in that order, and reads and executes commands from the first one that
exists and is readable.
whereas
When an interactive shell that is not a login shell is started, bash
reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if
these files exist.
Hence if the ruby environment variables are in /home/rails/.profile
or /etc/profile
for example, they will be added to the shell environment
- by explicitly invoking a login shell using
su -l rails
orsu --login rails
or the shorthandsu - rails
- when user
rails
logs in via SSH - by starting a subshell as
bash --login
after login
If you want the ruby environment to be set regardless of how you switch to user rails
, you could move the relevant variable definitions to the user's ~/.bashrc
instead.
Solution 2:
I know that this question was asked 2 years ago, but in case if somebody (like me) still facing it: @steeldriver is right -- you are missing something in your bashrc
which you do have in one of those 3 files. In my case I just needed to add this line into mine ~/.bashrc
:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"