Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Workaround for ubygems.rb / -rubygems parameter feature abruptly removed from Ruby. See
# Copyright:: 2018 Daniel Barrows
# License:: zlib/libpng
# Workaround for feature abruptly removed from Ruby.
# See
# Leave warn variable empty to not output the deprecation warning.
if ruby -e exit 2>&1 \
| grep 'cannot load such file -- ubygems (LoadError)' >/dev/null; then
which sudo >/dev/null 2>&1 && sudo=sudo
ruby_lib_dir="$( ruby -e 'exit 0' 2>&1 | grep 'cannot load such file' \
| sed 's,/rubygems/core_ext.\+,,' )"
if ! [ -z "$warn" ]; then
warning_msg="warn 'WARNING: -rubygems flag is deprecated. Use -rrubygems.'"
printf "#!/usr/bin/env ruby\n%s\nrequire 'rubygems'\n" "$warning_msg" \
| $sudo tee "$ruby_lib_dir/ubygems.rb" > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.