A simple script to check your ruby library version

Most ruby packages are not maintained by the Archlinux repository, I installed them locally then added ~/.gem/ruby/2.1.0/bin to $PATH.

Although the ruby version is 2.1.5, it uses 2.1.0 as the library version. It feels silly if I change it manually every time, so I have to find a way to check it automatically.

Refer to this post, the output of ruby -e 'puts $LOAD_PATH' includes what I need.

1
2
3
4
5
6
7
8
/usr/lib/ruby/site_ruby/2.2.0
/usr/lib/ruby/site_ruby/2.2.0/x86_64-linux
/usr/lib/ruby/site_ruby
/usr/lib/ruby/vendor_ruby/2.2.0
/usr/lib/ruby/vendor_ruby/2.2.0/x86_64-linux
/usr/lib/ruby/vendor_ruby
/usr/lib/ruby/2.2.0
/usr/lib/ruby/2.2.0/x86_64-linux

Then use sed and grep to find it out.

1
ruby -e 'puts $LOAD_PATH' | sed "s/\/usr\/lib\/ruby\///g" |grep '^[0-9\.]*$'

Finally I added the following line to .zshrc and it works fine.

1
2
ruby_version=`ruby -e 'puts $LOAD_PATH' | sed "s/\/usr\/lib\/ruby\///g" |grep '^[0-9\.]*$'`
path=($path ~/.gem/ruby/$ruby_version/bin)

BTW, this script can also be used in the PKGBUILD of ruby gem packages.