error linux
Linux Exit Code 127 - Command Not Found
Understanding Linux exit code 127 - the command could not be found in the system PATH or specified location.
What It Means
Exit code 127 indicates that the command could not be found. The shell searched the PATH and could not locate an executable with the given name. This means the program is either not installed, not in the system PATH, or the command name is misspelled.
Common Causes
- The program is not installed on the system
- Typo in the command name
- The program is installed but not in the system
PATH - Missing PATH entry after installing software
- Using a command from a virtual environment that isn’t activated
- Shell profile hasn’t been reloaded after installing new software
- Docker container missing the required package
How to Fix
Check if the command exists
# Check if the command is available
which node
command -v node
type node
# Search for the command
find / -name "node" -type f 2>/dev/null
# On Debian/Ubuntu: find which package provides a command
apt-file search --regexp 'bin/node$'
Install the missing package
# Debian/Ubuntu
sudo apt update && sudo apt install nodejs
# Red Hat/CentOS/Fedora
sudo yum install nodejs
# or
sudo dnf install nodejs
# macOS
brew install node
# Alpine (Docker)
apk add --no-cache nodejs
Fix the PATH
# Check current PATH
echo $PATH
# Add a directory to PATH temporarily
export PATH=$PATH:/usr/local/go/bin
# Add permanently to ~/.bashrc or ~/.zshrc
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrc
# Common PATH additions
export PATH=$PATH:$HOME/.local/bin # pip installs
export PATH=$PATH:$HOME/.cargo/bin # Rust
export PATH=$PATH:$HOME/go/bin # Go
export PATH=$PATH:./node_modules/.bin # npm local binaries
Fix in Docker
# Ensure packages are installed in Dockerfile
FROM node:20-alpine
# Install additional tools
RUN apk add --no-cache curl git bash
# Ensure npm global binaries are in PATH
ENV PATH="/usr/local/bin:${PATH}"
Fix in CI/CD
# GitHub Actions - ensure tools are available
steps:
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Use npx for local binaries
run: npx eslint . # Instead of just 'eslint .'
Use full path
# If the command exists but isn't in PATH
/usr/local/bin/node script.js
/opt/homebrew/bin/python3 script.py
Related Errors
- Linux Exit Code 126 - Not executable: The command was found but cannot be executed.
- Linux Exit Code 1 - General error: The command exists and ran, but failed.
- Linux Exit Code 2 - Misuse: The command exists but was used incorrectly.