8

I'm having trouble getting the Ruby Version Manager rvm to source from my Ubuntu 10.04 .profile. The code:

[[ -s "$HOME/.rvm/scripts/rvm" ] && . "$HOME/.rvm/scripts/rvm"

...never does what I expect it to (i.e. give me the rvm program when I open a new shell or start a new session); but if I execute

source .profile

in a new shell after logging in, it works! Why will it work when I manually source it, but not automatically at login?

Kara
  • 6,115
  • 16
  • 50
  • 57
bschuth
  • 135
  • 1
  • 8
  • Which shell are you using? Do you also have a .bash_profile? – SimonJ Oct 24 '10 at 02:53
  • Possible duplicate (or at least identical) question: http://stackoverflow.com/questions/3982244/postinstall-rvmruby-version-manager-without-root-access – joschi Dec 05 '10 at 07:38
  • How do you log in? I am using gdm3 and tried to source rvm from ~/.xprofile, but ~/.xprofile is run by /bin/sh and does not support that; in my case (hack) I modified /etc/gdm3/Xsession to use `#!/bin/bash`. Depending on the way you are logging in check whether .profile is really used (e.g. `PROFILE_USED=1; export PROFILE_USED`). If it is, it may be run by the wrong shell (it is only really meant to be run by /bin/sh "or better"); if it is not, try .xprofile. You're missing a ], too, but that's probably a typo here. – Thomas Luzat Dec 06 '15 at 12:53

4 Answers4

6

It would appear that Ubuntu handles it's logon scripts differently than most other linux distros

http://ubuntuforums.org/showpost.php?p=9127226&postcount=6

The above post has hints that GDM logins in Ubuntu don't process .bash_profile or .profile the way most other linux distros do. I have had to put the line loading RVM in the ~/.bashrc and that has not caused any problems yet.

BeepDog
  • 5,016
  • 2
  • 24
  • 33
3

Sourcing $HOME/.rvm assumes you have installed RVM a single user, specially, the user whose home directory is $HOME. Likely, on your Ubuntu system, RVM has been installed system wide, and thus you must source the RVM scripts as such:

In your .bashrc file add:

\# Set rvm path

[[ -s "/usr/local/rvm/scripts/rvm" ]] && source "/usr/local/rvm/scripts/rvm"

before this line; this line will exit and not execute anything past it, which is fine for interactive logins, bit would be a problem is you are using non-interactive SSH logins for automation purposes.

\# If not running interactively, don't do anything

[ -z "$PS1" ] && return
Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
DJM
  • 31
  • 1
0

I had a problem with Atom editor not picking up RVM environment and thus not finding rubocop command on Ubuntu 16.04. But the problem was not there when I started Atom from gnome terminal. What I've found was that RVM script ~/.rvm/scripts/rvm that you're supposed to be loading in your .profile has these lines at the beginning:

if
  builtin test -n "${BASH_VERSION:-}" -o -n "${ZSH_VERSION:-}" -o -n "${KSH_VERSION:-}"
then
  ...
else
  return 0
fi

Strangely, when executed at login, I've found $BASH_VERSION to be empty (while in gnome terminal it's sth like 4.3.46(1)-release), so the script would do early return leaving RVM not loaded properly. I tried to set BASH_VERSION to whatever and it worked fine.

Here is the complete code from my .profile that loads RVM:

local rvm_home="${HOME}/.rvm"
export PATH="$PATH:${rvm_home}/bin"
if [ -z "$BASH_VERSION" ]; then
    export BASH_VERSION=4
fi
source "${rvm_home}/scripts/rvm"
tsayen
  • 2,875
  • 3
  • 18
  • 21
0

The RVM installation page has a series of things to check to test the initialization of RVM. Read the "Troubleshooting your Install" section at the end of the RVM installation page.

Also, here's a description of how Bash reads its startup files which can help with this sort of problem.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303