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 or rvm 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!
22 Answers
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 railsorsu --login railsor the shorthandsu - rails - when user
railslogs in via SSH - by starting a subshell as
bash --loginafter 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.
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"