ruby/setup-ruby
Install Ruby and, with one input, install and cache your gems via Bundler.
What it does
ruby/setup-ruby installs a Ruby version (faster than the runner default) and, when bundler-cache: true, runs bundle install and caches the installed gems keyed on Gemfile.lock.
It reads the version from .ruby-version or .tool-versions automatically when present.
Usage
workflow (.yml)
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
bundler-cache: true
- run: bundle exec rakeInputs
| Input | Description | Default | Required |
|---|---|---|---|
ruby-version | Ruby version, e.g. 3.3. Reads .ruby-version if omitted. | .ruby-version | No |
bundler-cache | Run bundle install and cache the gems. | false | No |
working-directory | Directory containing the Gemfile. | . | No |
Outputs
| Output | Description |
|---|---|
ruby-prefix | Install path of the Ruby. |
ruby-platform | The platform of the installed Ruby. |
Notes
bundler-cache: true replaces a separate bundle install plus actions/cache step.
Common errors
- A slow job re-running bundle install every time usually has
bundler-cacheunset. Set it to true. - A Gemfile in a subfolder needs
working-directoryset so caching keys on the right lockfile.
Security and pinning
- Pin to a commit SHA (the @v1 tag moves).
Frequently asked questions
Do I need a separate cache step for gems?
No. Set
bundler-cache: true and setup-ruby runs bundle install and caches the gems for you.