Environment Variables and PATH Issues — Command Not Found and Configuration on Linux
Informationalsystem
Overview
Fix Linux environment variable and PATH issues including command not found errors, variables not persisting, and profile vs rc file configuration.
Key Details
- PATH is an environment variable listing directories where the shell searches for executables
- Environment variables can be set in ~/.bashrc, ~/.profile, ~/.bash_profile, or /etc/environment
- Login shells read profile files; non-login shells (like terminal emulators) read rc files
- Variables set with 'export' persist for child processes; without export, they are local to the current shell
- Systemd services do not inherit user environment variables — they have their own environment
Common Causes
- Executable installed in a directory not listed in PATH (e.g., /usr/local/bin, ~/.local/bin)
- Variable set in .bashrc but using a login shell that reads .profile instead
- Variable not exported — available in current shell but not in child processes
- Systemd service not configured with the required environment variables
Steps
- 1Check current PATH: 'echo $PATH' — verify the directory containing the command is listed
- 2Add to PATH permanently: add 'export PATH="$HOME/.local/bin:$PATH"' to ~/.bashrc (Bash) or ~/.zshrc (Zsh)
- 3Apply changes immediately: 'source ~/.bashrc' or start a new terminal session
- 4For systemd services: add Environment= or EnvironmentFile= to the [Service] section of the unit file
- 5Debug shell startup: 'bash -x -l -c exit 2>&1 | head -50' to trace which files are loaded
Tags
environmentpathbashrcprofileshell
More in System
windows-C000021A-status-system-process-terminatedWindows Error 0xC000021A — STATUS SYSTEM PROCESS TERMINATED
Criticalwindows-C0000225-boot-configuration-errorWindows Error 0xC0000225 — Boot Configuration Error
Criticalwindows-C000000F-boot-selection-failedWindows Error 0xC000000F — Boot Selection Failed
Criticalwindows-80004005-unspecified-errorWindows Error 0x80004005 — Unspecified Error
Warningwindows-80070570-file-or-directory-corruptedWindows Error 0x80070570 — File or Directory Corrupted
Errorwindows-system-0xc0000185Windows Error 0xC0000185 — Boot Device Inaccessible
CriticalFrequently Asked Questions
.profile is read by login shells (SSH login, console login). .bashrc is read by interactive non-login shells (opening a terminal emulator). Many setups source .bashrc from .profile for consistency.