Skip to content

Instantly share code, notes, and snippets.

@juno
Last active June 16, 2022 01:24
Show Gist options
  • Select an option

  • Save juno/fe5a5886be16aa26fa96449c9a7886d5 to your computer and use it in GitHub Desktop.

Select an option

Save juno/fe5a5886be16aa26fa96449c9a7886d5 to your computer and use it in GitHub Desktop.

Revisions

  1. juno revised this gist Jun 16, 2022. No changes.
  2. juno revised this gist Jun 16, 2022. No changes.
  3. juno created this gist Jun 16, 2022.
    30 changes: 30 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    ## Usage

    ```console
    $ 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. 🎉
    22 changes: 22 additions & 0 deletions update-rubygems-bundler
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!/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}`