"rails: command not found" in CI
The shell could not find a rails executable. On a fresh runner the rails command exists only through the bundle (or a binstub), so calling it bare before installing or without bundle exec fails.
What this error means
A step calling rails ... exits 127 with "rails: command not found". The same command works locally where rails is on PATH via a global gem or rbenv shim.
bundler
$ rails db:migrate
/bin/sh: 1: rails: command not foundCommon causes
Not run through Bundler
rails is provided by the railties gem in the bundle. Without bundle exec or a binstub, the bare rails command is not on PATH.
Bundle not installed yet
The step runs before bundle install, so no gem executables exist.
Missing binstub
bin/rails was not committed or not generated, so there is no project-local launcher.
How to fix it
Invoke via Bundler or the binstub
- Use bundle exec rails ... or commit and call bin/rails ....
- Ensure bundle install (or ruby/setup-ruby with bundler-cache) ran first.
- Generate binstubs: bundle binstubs railties and commit bin/rails.
Terminal
bundle install
bundle exec rails db:migrate
# or: bin/rails db:migrateHow to prevent it
- Standardize on bundle exec rails or bin/rails in CI.
- Run bundle install before any rails command.
- Commit binstubs so the launcher is always present.
Related guides
"rspec: command not found" in CIFix "rspec: command not found" in CI - rspec is a bundled gem executable; run it via bundle exec or a binstub…
"bundle exec: command not found" for a gem binary in CIFix "bundler: command not found: X" / "could not find executable" when running bundle exec in CI - the gem pr…
Gem::LoadError: is not the version that was activated in CIFix "Gem::LoadError: X is not the version that bundler is using" / "already activated" in CI - a different ve…