spectral "command not found" (CLI not installed) in CI
The shell could not find the spectral executable because the Spectral CLI package is not installed on the runner. It is an npm package and is not preinstalled.
What this error means
A step calling spectral lint ... fails with "spectral: command not found" and the job exits with code 127.
/home/runner/work/_temp/script.sh: line 1: spectral: command not found
Error: Process completed with exit code 127.Common causes
The Spectral CLI is not installed
Without an explicit npm install -g @stoplight/spectral-cli, the spectral binary is absent from the runner PATH.
A local install is not on PATH
A project-local install lives under node_modules/.bin, which is not on PATH unless invoked through npx or a package script.
How to fix it
Install the Spectral CLI, then lint
- Install
@stoplight/spectral-cliglobally with npm. - Run
spectral lintagainst your spec. - Pin the CLI version for reproducibility.
- run: npm install -g @stoplight/spectral-cli
- run: spectral lint openapi.yamlRun through npx without a global install
npx fetches and runs the Spectral CLI on demand.
npx @stoplight/spectral-cli lint openapi.yamlHow to prevent it
- Install @stoplight/spectral-cli explicitly before the lint step.
- Prefer
npx @stoplight/spectral-clito avoid a global install. - Pin the CLI version so lint results are reproducible.