Skip to content
Latchkey

rbenv "ruby: command not found" - Shims Not on PATH in CI

The shell cannot find ruby (or bundle) on PATH because the rbenv shims directory is not present or rbenv was never initialized in this shell. The Ruby is installed; the shim that exposes it is just not active.

What this error means

A step calling ruby, gem, or bundle fails instantly with command not found, even though rbenv has the version installed. Common when an earlier step initialized rbenv but a later fresh shell did not.

Terminal
./bin/ci.sh: line 3: ruby: command not found
# or
bundle: command not found

Common causes

rbenv shims not on PATH

Without ~/.rbenv/shims on PATH, the shell never sees the rbenv-managed ruby/bundle shims, so the commands are not found.

rbenv not initialized in this shell

Each CI step is a fresh shell. An init done in one step does not carry to the next, so the shims are inactive again.

How to fix it

Initialize rbenv in each step that needs it

Terminal
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - bash)"
ruby --version

Persist rbenv to the job environment

On GitHub Actions, add the shims to GITHUB_PATH so every later step finds ruby.

.github/workflows/ci.yml
- run: |
    echo "$HOME/.rbenv/bin" >> "$GITHUB_PATH"
    echo "$HOME/.rbenv/shims" >> "$GITHUB_PATH"

How to prevent it

  • Use setup-ruby so Ruby is on PATH for every step.
  • Persist rbenv shims to the job PATH instead of per-step init.
  • Avoid relying on shell state carrying between CI steps.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →