Skip to content

Instantly share code, notes, and snippets.

@juno
Last active June 16, 2022 01:24
Show Gist options
  • Save juno/fe5a5886be16aa26fa96449c9a7886d5 to your computer and use it in GitHub Desktop.
Save juno/fe5a5886be16aa26fa96449c9a7886d5 to your computer and use it in GitHub Desktop.
πŸ’Ž Update rubygems and bundler for all installed (via asdf) ruby versions.

Usage

$ asdf list ruby
  2.7.4
  2.7.5
  2.7.6
  3.0.3
  3.1.2
  3.2.0-preview1

$ update-rubygems-bundler
----> Start rubygems and bundler update
      Current Ruby version: 3.1.2
      Target Ruby versions: 2.7.4, 2.7.5, 2.7.6, 3.0.3, 3.1.2, 3.2.0-preview1
----> 2.7.4: Updating ruby gems and bundler
      Done.
----> 2.7.5: Updating ruby gems and bundler
      Done.
----> 2.7.6: Updating ruby gems and bundler
      Done.
----> 3.0.3: Updating ruby gems and bundler
      Done.
----> 3.1.2: Updating ruby gems and bundler
      Done.
----> 3.2.0-preview1: Updating ruby gems and bundler
      Done.

that's all. πŸŽ‰

#!/usr/bin/env ruby
require "shellwords"
puts "----> Start rubygems and bundler update"
# store current ruby version
current_version = `asdf current ruby | cut -w -f 2`.strip
puts " Current Ruby version: #{current_version}"
# update rubygems and bundler for each installed versions
versions = `asdf list ruby`.split("\n").map(&:strip)
puts " Target Ruby versions: #{versions.join(", ")}"
versions.each do |version|
puts "----> #{version}: Updating ruby gems and bundler"
`asdf global ruby #{version.shellescape}`
`gem update --system`
puts " Done."
end
# restore ruby version
`asdf global ruby #{current_version.shellescape}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment