Skip to content

Instantly share code, notes, and snippets.

@garrettdimon
Last active September 10, 2024 19:59
Show Gist options
  • Save garrettdimon/2c8108dfaafccc0553fef195b88efe70 to your computer and use it in GitHub Desktop.
Save garrettdimon/2c8108dfaafccc0553fef195b88efe70 to your computer and use it in GitHub Desktop.
One Command for Bumping Ruby Versions when using rbenv
#/usr/bin/env bash
echo "---"
# Exit on error
set -o errexit
# Get the version from the .ruby-version file
target_ruby_version=$(cat .ruby-version)
# Get the full version from the local ruby
current_ruby_version=`ruby -e 'puts RUBY_VERSION'`
if [ "$target_ruby_version" != "$current_ruby_version" ]; then
echo "Upgrading Ruby from $current_ruby_version to $target_ruby_version"
# Make sure the latest Ruby versions are present and available
arch -arm64 brew update && arch -arm64 brew upgrade ruby-build
# Install the version specified in the .ruby-version file
rbenv install --skip-existing $target_ruby_version
if [ -f Gemfile.lock ]; then
# Wipe out the Gemfile.lock file
# Note: This is somewhat aggressive, but it helps expose issues sooner.
# With projects that have a more brittle set of Gems, it may be best to
# take a more forgiving approach.
#
# When using this, running `bundle update` below instead of `bundle install`
# as another way to try an aggressive update. Really only advised for
# projects that are obssessive about staying current on dependencies.
rm Gemfile.lock
fi
else
echo "Ruby version is current at $current_ruby_version"
fi
echo "---"
# Update Bundler to the latest
bundle update --bundler
# Re-bundle and ensure linux is added
bundle install
bundle lock --add-platform x86_64-linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment