Skip to content

Instantly share code, notes, and snippets.

@ninthspace
Last active November 9, 2018 12:03
Show Gist options
  • Save ninthspace/4360267 to your computer and use it in GitHub Desktop.
Save ninthspace/4360267 to your computer and use it in GitHub Desktop.
How I migrated from rbenv to chruby, and kept per-project gems nice and tidy.

Remove rbenv and any rubies, gems etc.:

$ rm -rf ~/.rbenv

Uninstall rbenv if installed via Homebrew

$ brew uninstall rbenv

Remove references to rbenv in ~/.bash_profile etc.

Install chruby as per https://github.com/postmodern/chruby

For easy of use I decided to add the following to ~/.bash_profile

RUBIES=(/Users/chris/.rubies/rub*)
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh

The first line ensures I know where my rubies are installed, and the latter line auto-switches ruby versions, honouring the setting in .ruby-version when entering a directory.

Open a new shell so the above takes effect.

Install rubies via ruby-build https://github.com/sstephenson/ruby-build

Because I've now no gems, install Bundler

$ gem install bundler

At this stage, I still need project-specific gems. Previously I've used rbenv-gemset (and prior to that rvm's own management). Now I decided to just rely on Bundler.

So, go to each project and:

  • Switch to the required ruby using chruby
  • Put that ruby version in a .ruby-version file

Then Bundle as follows:

$ bundle install --path vendor
$ bundle package --all
$ echo 'vendor/ruby' >> .gitignore

Tips for the above came from http://ryan.mcgeary.org/2011/02/09/vendor-everything-still-applies/

Use bundle exec rails server etc., as before

@postmodern
Copy link

Note, chruby supports auto-detection of Rubies in ~/.rubies/ and /opt/rubies/. Also, you can configure chruby to use rbenv's rubies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment