Skip to content

Instantly share code, notes, and snippets.

@pbt001
Forked from jhass/RubyOnArch.md
Created December 31, 2019 01:05
Show Gist options
  • Save pbt001/1847d1e0669351ca0d9ca9abe1d86da2 to your computer and use it in GitHub Desktop.
Save pbt001/1847d1e0669351ca0d9ca9abe1d86da2 to your computer and use it in GitHub Desktop.
My Ruby setup on Archlinux

Ruby on Archlinux

I thought I would document my setup, since it's somewhat non-standard but working quite well for me.

What this does

  • Install major Ruby versions at their latest patch release
  • Allow to switch between them seamlessly
  • Use chruby
  • Encourage bundler usage

What this does not

  • 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.

Setup

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

Upgrading

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

Per project setup

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.

System wide gem installation

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.

Scripting

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.

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