How to Switch to Another Ruby Version (temporarily, per project, or globally) Using rbenv
In this mini post I’ll show you how to switch to another ruby versions using rbenv. Unlike RVM, rbenv does not offer a command like
rvm use but will always respect your project’s
You have several options:
But choose wisely, for while the true command will bring you life, the false command will take it from you.
Temporarily: rbenv shell
Changes your Ruby version on your current shell:
$ ruby -v ruby 1.9.3p484 (...) $ rbenv shell 2.0.0-p353 $ ruby -v ruby 2.0.0p353 (...)
Background: This actually sets the
RBENV_VERSION environment variable in your terminal session.
Per project: rbenv local
$ ruby -v ruby 1.9.3p484 (...) $ rbenv local 2.0.0-p353 $ ruby -v ruby 2.0.0p353 (...)
…but actually writes that version to a
.ruby-version in your current directory. Use this only when you want to change the Ruby version on a project, not to change it temporarily (as you’d change your project’s file or clutter whatever directory you are currently in with that file).
Globally: rbenv global
This will also change your Ruby version, but only the one you are using whenever no other version is specified, e.g. via a
.ruby-version file or
$ ruby -v ruby 1.9.3p484 (...) $ rbenv global 2.0.0-p353 $ ruby -v ruby 2.0.0p353 (...) $ echo "1.9.3p484" > .ruby-version $ rbenv global 2.0.0-p353 $ ruby -v ruby 1.9.3p484 (...)
Note that this is really your global Ruby version, so calling that on one terminal session will affect other terminal sessions as well – unless they are inside a directory tree using
.ruby-version, of course.
If You Appreciate What We Do Here On Mimastech, You Should Consider:
- Stay Connected to: Facebook | Twitter | Google+
- Support us via PayPal Donation
- Subscribe to our email newsletters.
- Tell other sysadmins / friends about Us - Share and Like our posts and services
We are thankful for your never ending support.