Skip to content

Instantly share code, notes, and snippets.

@timblair
Last active August 29, 2015 14:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timblair/9745d10e9a7af6f6aa43 to your computer and use it in GitHub Desktop.
Save timblair/9745d10e9a7af6f6aa43 to your computer and use it in GitHub Desktop.
Use rbenv? Need to update All The Rubies™ because of Bundler's BUNDLED_WITH change? Then use this script.
#!/bin/bash
eval "$(rbenv init -)"
CURRENT_RUBY=$(rbenv version-name)
LATEST_BUNDLER=$(curl -s https://rubygems.org/api/v1/versions/bundler/latest.json | cut -d'"' -f 4)
echo "Latest Bundler version: $LATEST_BUNDLER"
for RUBY_VERSION in $(rbenv versions --bare); do
rbenv shell "$RUBY_VERSION"
if $(gem list -i bundler); then
CURRENT_BUNDLER=$(bundle --version | cut -d" " -f3)
if [ "$CURRENT_BUNDLER" != "$LATEST_BUNDLER" ]; then
echo "Updating $RUBY_VERSION Bundler from $CURRENT_BUNDLER"
# Rubygems versions < 2.3.0 use a regex for `update` commands
OLD_RUBYGEMS="abort if Gem::Version.new('$(gem --version)') >= Gem::Version.new('2.3.0')"
if $(ruby -r rubygems -e "$OLD_RUBYGEMS"); then
gem update ^bundler$
else
gem update bundler
fi
else
echo "Ruby $RUBY_VERSION already has the latest Bundler"
fi
else
echo "No Bundler version in $RUBY_VERSION"
gem install bundler
fi
done
echo "All done. Switching back to $CURRENT_RUBY"
rbenv shell "$CURRENT_RUBY"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment