CNK's blog

Emacs and RVM

I have been using RVM for several years - straight in the terminal and in a bash shell in emacs. But all of a sudden I started having path problems. I don’t remember having updated my RVM version, though I quite possibly I did before I updated my installed rubies for the latest security patches. Or perhaps there is some odd interaction with the ruby that got installed when I installed the Heroku toolbelt (v 3.2.0) this last week; it appears to have installed it’s own ruby in /usr/local/heroku/ruby/bin/ruby but then added /usr/local/heroku/bin with export PATH="/usr/local/heroku/bin:$PATH" in my .bashrc.

The symptom was that in my bash shell within emacs I was getting warnings about RVM not finding what it expected at the start of my path. I should have copied the error message but it was expecting something like /Users/cnk/.rvm/gems/ruby-2.0.0-p353/bin. Initially I was getting a path starting with /usr/local/heroku/bin because the Heroku Toolbelt install had placed that line at the end of my .bashrc file. But even after having moved the heroku line into my .profile before the rvm line, I was still getting oddities when trying to use knive (installed with the chef gem). I tried the fixed suggested in the warning message: rvm get stable --auto-dotfiles. That gave me version 1.25.14. and made modifications to my dotfiles:

$ rvm get stable --auto-dotfiles
Turning on auto dotfiles mode.

Upgrading the RVM installation in /Users/cnk/.rvm/
    Removing rvm PATH line from /Users/cnk/.zshrc.
    Adding rvm PATH line to /Users/cnk/.profile /Users/cnk/.bashrc /Users/cnk/.zshrc.
    Removing rvm loading line from /Users/cnk/.bashrc /Users/cnk/.zlogin.
    Adding rvm loading line to /Users/cnk/.bash_profile /Users/cnk/.zlogin.
Upgrade of RVM in /Users/cnk/.rvm/ is complete.

That made everything work in the terminal but made it much worse in emacs. With the default rvm setup (source "$HOME/.rvm/scripts/rvm" in my .bash_profile file), rvm was not getting loaded in my emacs shell. type -t rvm was returning ‘file’ instead of ‘function’ and none of my rvm commands would work - no rvm use or rvm gemset list. I fooled around for a bit and sorted out that what I need to get rvm to work in the terminal AND in my emacs shell is to have this line in my .bashrc file NOT in .bash_profile or .profile:

# Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

That works fine and does not seem to have any problems even if I create a new shell within an old one.

Other RVM and Emacs Options

There are a couple of more sophisticated ways of using rvm within emacs that I came across while trying to figure out why this had suddenly stopped working. One of these days I should look at them:

Path Warnings Redux

I got the same warning again today - when changing directories from within a shell running in emacs:

[04:12 PM] (brazen:~/chef-tdd) $ rvm list
Warning! PATH is not properly set up, '/Users/cnk/.rvm/gems/ruby-2.0.0-p353/bin' is not available,
         usually this is caused by shell initialization files - check them for 'PATH=...' entries,
         it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
         to fix temporarily in this shell session run: 'rvm use ruby-2.0.0-p353'.

rvm rubies

   ruby-1.9.3-p374 [ x86_64 ]
   ruby-1.9.3-p484 [ x86_64 ]
   ruby-2.0.0-p0 [ x86_64 ]
=* ruby-2.0.0-p353 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

This time a) I remembered to record it and b) I read the full message! I went with the last option: rvm use ruby-2.0.0-p353. Running that command got me the same warning again - but once the command executed, then all was repaired and the rest of the commands work fine, e.g. rvm list, rvm gemset list, etc.