"RubyGems were not loaded." error when attempting to install gems into the installation directory

After a lot of trial and error, and looking at other snapcraft.yml examples, I ended up having to copy the installed gems using cp -R from /var/lib/gems/ into the $SNAPCRAFT_PART_INSTALL/var/lib/gems/ and the executables installed into /usr/local/bin/ into $SNAPCRAFT_PART_INSTALL/usr/bin/, as well as explicitly setting RUBYLIB, GEM_HOME, and GEM_PATH for the app commands. Only then could ruby load rubygems and load the other gem(s).

https://github.com/ronin-rb/snap/blob/2b98d2ad9fd7077037d65d21639d057717684b5e/snap/snapcraft.yaml

Not sure if this is the best way to package a rubygem, but until the ruby plugin is updated to core20 or core22, this seems to be the only way to get it working.

2 Likes