I am very new to Emacs. In my case what I'm actually using is Spacemacs.

I have few versions of Ruby installed in my system and I use RVM for switching between them.

I'm trying to change current version of Ruby when working on some project by pressing M-x and entering command rvm-use and then selecting the version I need, but it only changes Ruby version for the current buffer and when I open a new file of the same project I can see that Ruby version is back to previous one.

Is there any way to persist the setting for whole Emacs session (or persist it for all files in the current directory) so it only gets reset when I restart Emacs (or when I change current directory)? I don't actually know if it's something specific to rvm.el or Emacs, but I can't find a way to achieve what I want.

Now the only way for me to achieve that is to run rvm *needed_version* --default in the shell, but that changes the version for whole operating system, and I would prefer to limit the effect to Emacs only. When working in OS X terminal I can just run rvm *needed_version* and it changes rvm version for whole terminal session but without affecting other sessions, but I can't find a way to achieve the same in Emacs.

2 Answers 2


Spacemacs has a variable for this in the Ruby layer. I assume you already have the layer enabled since you are working in Ruby buffers. The documentation for Ruby version management is here: https://github.com/syl20bnr/spacemacs/blob/master/layers/%2Blang/ruby/README.org#ruby-version-management

Basically, it tells you to configure this variable in the configuration layers list like this:

(defun dotspacemacs-configuration-layers ()
   '((ruby :variables ruby-version-manager 'rvm)))

From the docs:

When a version manager is enabled it will use the currently activated ruby except if a .ruby-version file exists in which case the ruby version of this file is used. rvm will also try to look for a .rvmrc and gemfile, the priority order is .rvmrc then .ruby-version then gemfile.

  • Thanks! That did help a lot. I actually had it enabled already but what I was missing was "ruby "2.4.0"" in my Gemfile.
    – Bo Yi
    Commented Jan 27, 2019 at 2:56
  • You're welcome! Is there still something unanswered in your question? I reread it and thought maybe there is something more you're trying to get.
    – shoshin
    Commented Jan 27, 2019 at 16:01
  • Yeah, I'm actually still wondering if it's possible to run "rvm-use" (or any other emacs command) so it affects all buffers and is active until i restart Emacs. Or is the effect of all commands like that limited to the buffer they've been run in?
    – Bo Yi
    Commented Jan 27, 2019 at 17:22
  • I think rvm-use should behave like you're expecting. I'm wondering if the spacemacs ruby layer is conflicting with the behavior you want, because it adds a hook to run rvm-activate-corresponding-ruby when entering ruby-mode. So it is probably being set according to those rules. To answer your question, there are per-buffer commands and global commands. You'd just need to read the documentation of the command you're using.
    – shoshin
    Commented Jan 28, 2019 at 3:35
  • oh! I got what you mean. that makes a lot of sense now! Thank you so much :)
    – Bo Yi
    Commented Jan 28, 2019 at 9:09

You want to run a command every time a ruby-mode buffer is opened or a buffer change to ruby-mode. You should use a hook.

(add-hook 'ruby-mode-hook
      (lambda ()

Insert the wanted command and put that code in your init file.

  • Thanks! And is it possible to run this command on the fly without touching the init file? Cuz otherwise I would need to add it to init file, then resync configuration to apply the changes. And then when I am done and need to go to another project that needs different Ruby version, I would need to change init file and resync configuration again. Or is updating init file and resyncing actually the simplest way to achieve this?
    – Bo Yi
    Commented Jan 27, 2019 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.