Environment Variables and PATH Issues — Command Not Found and Configuration on Linux
About Environment Variables and PATH Issues
Fix Linux environment variable and PATH issues including command not found errors, variables not persisting, and profile vs rc file configuration. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.
Here are the key things to understand: 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. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.
The most common reasons this occurs include: 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. Identifying the root cause is the first step toward finding the right solution.
To resolve this, follow these recommended steps: Check current PATH: 'echo $PATH' — verify the directory containing the command is listed. Add to PATH permanently: add 'export PATH="$HOME/.local/bin:$PATH"' to ~/.bashrc (Bash) or ~/.zshrc (Zsh). Apply changes immediately: 'source ~/.bashrc' or start a new terminal session. For systemd services: add Environment= or EnvironmentFile= to the [Service] section of the unit file. Debug shell startup: 'bash -x -l -c exit 2>&1 | head -50' to trace which files are loaded. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.
This article is part of our Linux Error Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.
Quick Answer
What is the difference between .bashrc and .profile?
.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.
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