Ruby "rails: command not found" in CI - Fix Binstubs & bundle exec
The shell could not find a rails executable on PATH. The rails gem is in your bundle, but its binary is not globally installed - you reach it through Bundler or a binstub, not a bare rails call.
What this error means
A step calling rails ... fails with "rails: command not found", even though the rails gem installed successfully. The binary simply is not on PATH for a direct invocation.
./bin/ci.sh: line 8: rails: command not foundCommon causes
rails binary not on PATH
A bundled gem’s executable is not placed on the global PATH. Running bare rails only works if rails is installed system-wide, which it usually is not in CI.
Binstubs not generated or not committed
If bin/rails was not generated (or is gitignored), there is no project-local launcher, so the bare command has nothing to resolve to.
How to fix it
Run rails through Bundler or its binstub
Use bundle exec, or generate and call the binstub.
bundle exec rails db:migrate
# or generate binstubs and call them
bundle binstubs railties --force
bin/rails db:migrateCommit binstubs so CI can call bin/rails
- Generate bin/rails locally (rails app:update:bin or bundle binstubs).
- Commit the bin/ directory so it is present in the checkout.
- Ensure bin/ is on PATH or call ./bin/rails explicitly.
How to prevent it
- Call project executables via bundle exec or committed binstubs in CI.
- Commit the bin/ directory (binstubs) to the repo.
- Avoid relying on globally installed gem binaries in pipelines.