I thought I would document my setup, since it's somewhat non-standard but working quite well for me.
- Install major Ruby versions at their latest patch release
- Allow to switch between them seamlessly
- Use chruby
- Encourage bundler usage
- Install files outside your home folder that are not tracked by your package manager
- Use ruby-install, ruby-build, rbenv or RVM
- Allow you to switch to a specific outdated patchlevel version of Ruby, out of the box.
yay
is used as an example AUR helper, use whichever you like or do it manually. Prefixed with #
means run as root, prefixed with $
means run as the user you regularly work with.
# pacman -S ruby
$ yay -S chruby ruby-bundler
$ mkdir -p ~/.rubies/2.6/bin
$ ln -s /usr/bin/ruby ~/.rubies/2.6/bin/ruby
$ echo "gem: --no-user-install --env-shebang" > ~/.gemrc
Edit your ~/.$SHELLrc
and add:
# chruby
source /usr/share/chruby/chruby.sh
source /usr/share/chruby/auto.sh
RUBIES=(/opt/ruby* $HOME/.rubies/*)
Optionally, but the entire point of this setup, install older Ruby versions:
$ yay -S ruby2.4 ruby2.4-bundler ruby2.5 ruby2.5-bundler
When the ruby package moves to a new minor or major version (major.minor.teensy
), do the following (adjusting the versions of course):
$ mv ~/.rubies/2.6 ~/.rubies/2.7
Most likely I will upload a package for the old release to the AUR:
$ yay -S ruby2.6
Create a .ruby-version
file with the desired version to use, like
2.4
Use a Gemfile
and bundle install
to install gems into your home folder, or bundle install --path vendor/bundle
to install gems to a per project directory.
Do not do gem install
as root, install the packages from the AUR like we already did for ruby-bundler
, ruby2.1-bundler
and so on. If the gem you want to install system wide isn't packaged yet, create one! Have a look at existing packages for inspiration or facilitate tools like gem2arch.
Use /usr/bin/chruby-exec 2.4 -- regular command
to switch to a different Ruby environment in your scripts. This only works for scripts run as users that have this setup. Same holds true for systemd units, while you can use chruby-exec
in ExecStart
and friends, your service needs to have a User=
to one with this setup.