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"
Related videos on Youtube
Ole Henrik Skogstrøm
Updated on September 18, 2022Comments
-
Ole Henrik Skogstrøm over 1 year
I have just setup a new Ubuntu 13.10 server with ruby 2.1.1 installed through
rvm
.The problem is that whenever I switch to the user "rails" (the user I installed ruby and rails with) I have to run
/bin/bash --login
before Ubuntu recognises that ruby, rails orrvm
is installed.Hope someone knows:
- What does the command above do?
- why do i need to run it?
- and what can i do to solve it once and for all? :)
Any help is appreciated!
-
steeldriver about 10 yearsHow are you switching to user "rails" (plain
su
? or something likesu -l
orsu --
?). What is the login shell for user "rails"? Did you modify the user's PATH variable and if so in which file (~/.profile
or~/.bashrc
or~/.bash_profile
or ... ?) -
Ole Henrik Skogstrøm about 10 yearsI see now that the problem only occurs when i use the su command to switch from root to the rails user. When i ssh in with the rails user this problem does not happen. However i would still like to know what /bin/bash --login does. :)
-
Ole Henrik Skogstrøm about 10 yearsHmmm, ok, i think i need an example of the last part. I'm new to linux and ubuntu. What are the relevant variable definitions? In what file are they written now? could you give me an example? This is a bit to theoretical.