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/3.0/bin
$ ln -s /usr/bin/ruby ~/.rubies/3.0/bin/ruby
$ echo "gem: --no-user-install --env-shebang" > ~/.gemrcUnfortunately the ruby2.7 package in community changed the packaging style compared to what has been done historically. To make it available we need another symlink:
$ mkdir -p ~/.rubies/2.7/bin
$ ln -s /usr/bin/ruby-2.7 ~/.rubies/2.7/bin/rubyEdit 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.6 ruby2.6-bundler ruby2.7If you want to make other Ruby distributions available just add them to RUBIES if they provide a bin/ruby. Else symlink them into .rubies like we did above for ruby2.7.
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/3.0 ~/.rubies/3.1Most likely I or somebody else will upload a package for the old release to the AUR:
$ yay -S ruby3.0Depending on how it's packaged you might need to add a new symlink to .rubies.
Create a .ruby-version file with the desired version to use, like
2.7
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.7-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.7 -- 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.
Why do you use the AUR version? Is it better? Isn't better to use
$ sudo pacman -S ruby? Thanks!