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:
A login shell is one whose first character of argument zero is a -, or
one started with the --login option.
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.
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
/etc/profile for example, they will be added to the shell environment
- by explicitly invoking a login shell using
su -l rails or
su --login rails or the shorthand
su - 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