[Ruby Installation] Install multiple Ruby versions on macOS
Multiple Ruby versions
Using a Ruby version manager is critical if you plan on running many projects with different Ruby version. A project might not be compatible with the version of Ruby you have installed. We need a way to switch between versions of Ruby without installing and uninstalling them every time.
We need a way to switch between versions of Ruby without installing and uninstalling them every time.
There are two different ways to install and run multiple Ruby versions.
-
Host Mode - Install and run Ruby within host or virtual machine by Ruby Version Manager(RVM), asdf or rbenv.
-
Container Mode - Install and run Ruby within container by Docker and Docker Compose, or Kuberneters(K8S).
Prerequisites
-
Xcode Command Line Tools
The Xcode Command Line Tools Package is a small self-contained package available for download separately from Xcode and that allows you to do command line development in macOS which is consists of the macOS SDK and command-line tools such as Clang, which are installed at thisFor more information about installing and using Xcode Command Line Tools, see the Xcode Command Line Tools
-
Homebrew
Homebrew is the Missing Package Manager for macOS (or Linux).For more information about installing and using Homebrew, see the Homebrew - https://brew.sh/.
1. Host Mode
Install and run Ruby within host or virtual machine by Ruby Version Manager(RVM), asdf or rbenv.
1.1. Ruby Version Manager(RVM)
Ruby Version Manager(RVM) is a command-line tool which allows you to easily install, manage, and work with multiple Ruby environments from interpreters to sets of gems.
1 | Install GPG keys |
See RVM: Ruby Version Manager - Installing RVM - https://rvm.io/rvm/install#installation to learn more.
1.2. asdf
Manage multiple runtime versions with a single CLI tool, extendable via plugins - docs at asdf-vm.com.
asdf is a CLI tool that can manage multiple language runtime versions on a per-project basis. It is like gvm, nvm, rbenv & pyenv (and more) all in one! Simply install your language’s plugin!
Install asdf.
1 | Install asdf dependencies |
Install asdf Ruby Plugin.
1 | Install Ruby plugin requirements |
Update Ruby plugin.
1 | asdf plugin update ruby |
List all Ruby versions.
1 | asdf list all ruby |
Install a Ruby version manually.
1 | asdf install ruby 2.7.2 |
See follow links to learn more:
All Plugins - https://asdf-vm.com/#/plugins-all
asdf-vm/asdf-ruby: Ruby plugin for asdf version manager - https://github.com/asdf-vm/asdf-ruby
1.3. rbenv
Groom your app’s Ruby environment with rbenv.
Use rbenv to pick a Ruby version for your application and guarantee that your development environment matches production. Put rbenv to work with Bundler for painless Ruby upgrades and bulletproof deployments.
rbenv/rbenv: Groom your app’s Ruby environment - https://github.com/rbenv/rbenv
Compatibility note: rbenv is incompatible with RVM. Please make sure to fully uninstall RVM and remove any references to it from your shell initialization files before installing rbenv.
2. Container Mode
Install and run Ruby within container by Docker and Docker Compose, or Kuberneters(K8S).
2.1 Docker and Docker Compose
Create or update Dockerfile
.
1 | # Dockerfile |
Build docker image and run container.
1 | docker build -t my-ruby-app . |
docker-compose.yml
describes the services that comprise your app (a database and a web app), how to get each one’s Docker image (the database just runs on a pre-made PostgreSQL image, and the web app is built from the current directory), and the configuration needed to link them together and expose the web app’s port.
1 | version: "3.9" |
You can now boot the app with docker-compose up:
1 | docker-compose up |
See follow links to learn more.
Install Docker Engine | Docker Documentation - https://docs.docker.com/engine/install/
Install Docker Compose | Docker Documentation - https://docs.docker.com/compose/install/
Quickstart: Compose and Rails | Docker Documentation - https://docs.docker.com/compose/rails/
2.2 Kubernetes (K8S)
Create or update k8s manifests file k8s.yml
.
1 | # k8s.yml |
1 | kubectl create -f k8s.yml |
References
[1] RVM: Ruby Version Manager - Installing RVM - https://rvm.io/rvm/install#installation
[3] All Plugins - https://asdf-vm.com/#/plugins-all
[4] asdf-vm/asdf-ruby: Ruby plugin for asdf version manager - https://github.com/asdf-vm/asdf-ruby
[5] Install Docker Engine | Docker Documentation - https://docs.docker.com/engine/install/
[6] Install Docker Compose | Docker Documentation - https://docs.docker.com/compose/install/
[7] Quickstart: Compose and Rails | Docker Documentation - https://docs.docker.com/compose/rails/
[8] Ruby - Official Image | Docker Hub - https://hub.docker.com/_/ruby
[8] rbenv/rbenv: Groom your app’s Ruby environment - https://github.com/rbenv/rbenv
[10] Schniz/fnm: 🚀 Fast and simple Node.js version manager, built in Rust - https://github.com/Schniz/fnm
[12] Install Ruby with Frum · Mac Install Guide - https://mac.install.guide/ruby/14.html
[13] [Deploying Ruby on Rails Apps on Kubernetes | Littlelines - https://littlelines.com/blog/2020/04/08/deploying-ruby-on-rails-apps-on-kubernetes)(https://littlelines.com/blog/2020/04/08/deploying-ruby-on-rails-apps-on-kubernetes)