I wanted to install pre-compiled Ruby. It should exist! Then I thought up Homebrew. Almost every formula of Homebrew has “bottles” for multiple versions of macOS. So I thought: ‘Just use Homebrew Ruby with chruby!’
Homebrew Ruby is keg-only since 2.5.3, so if you had installed Homebrew Ruby earlier than or equal to 2.5.3, make sure to unlink it. Binaries of gems were placed under /usr/local/bin/
, so they can make problems related to PATH.
brew unlink ruby
By default, ruby-install installs Rubies into ~/.rubies
. If you install Ruby 2.6.0 using ruby-install ruby 2.6.0
, then the Ruby goes to ~/.rubies/ruby-2.6.0
. So what if we make a symbolic link under ~/.rubies
pointing Homebrew Ruby?
ln -s "$(brew --prefix)/Cellar/ruby/2.6.0" ~/.rubies/ruby-2.6.0
Specify ruby-2.6.0
in ~/.ruby-version
, and opening a new shell works like a charm!
$ chruby
* ruby-2.6.0
Although chruby sets $GEM_HOME
and $GEM_PATH
properly, Homebrew intentionally removes binaries of bundled gems on installation, so you have to install them using gem install
.
gem install bundler
gem install irb
Not only when a new Ruby is released, but also Homebrew sometimes updates Ruby for a new revision. The symlink is based on the cellar, so the link should be updated.
ln -sfn "$(brew --prefix)/Cellar/ruby/2.6.0_1" ~/.rubies/ruby-2.6.0
No more compiling time!