Skip to content

Instantly share code, notes, and snippets.

@rubyandcoffee
Last active February 23, 2024 11:34
Show Gist options
  • Save rubyandcoffee/5f15410a6c729f06b85f27cdc04cc20e to your computer and use it in GitHub Desktop.
Save rubyandcoffee/5f15410a6c729f06b85f27cdc04cc20e to your computer and use it in GitHub Desktop.
chruby - Installing and managing Ruby versions
To install chruby and ruby-install:
brew install chruby ruby-install
To install Ruby using ruby-install:
ruby-install ruby 2.7.1
NOTE: You can find latest stable version of Ruby here: https://www.ruby-lang.org/en/downloads/
If you have issues installing Ruby then try the following:
brew install openssl@3
ruby-install 3.2.2 -- --with-openssl-dir=$(brew --prefix openssl@3)
chruby 3.2.2
Note: If you'd just installed a new Ruby version and chruby can't find it, it means you need to reload the terminal.
Add following to ~/.bash_profile or ~/.zshrc:
echo 'source /usr/local/opt/chruby/share/chruby/chruby.sh' >> ~/.bash_profile
echo 'source /usr/local/opt/chruby/share/chruby/auto.sh' >> ~/.bash_profile
(auto.sh above enables auto-switching if Rubies specified by .ruby-version files)
To switch Ruby versions:
chruby 2.7.1
If you get this error: "zsh: command not found: chruby"
then you need to reload bash profile: $ source ~/.bash_profile
To list available Ruby versions:
chruby
To install Rails:
gem install rails -v 6.0.3.2 --no-document
If after this, you try to use a Rails command, e.g. $ rails new ...
and you receive the following error: "Rails is not currently installed on this system"
1) Then just open a new tab and/or reload bash profile,
2) Switch to the Ruby version (e.g. 3.1.2)
3) Re-run required Rails command
Further information:
https://github.com/postmodern/chruby
https://blog.engineyard.com/how-to-install-ruby-on-a-mac-with-chruby-rbenv-or-rvm
https://ryanbigg.com/2015/06/mac-os-x-ruby-ruby-install-chruby-and-you
Other chruby gists:
- https://gist.github.com/rubyandcoffee/83b7bdffc8faf909e077da58ca1ec7ec
@dannykennedy
Copy link

ruby-install ruby 2.7.1 should be ruby-install ruby-2.7.1, it seems...

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