Error Codes Wiki

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

  1. 1Check current PATH: 'echo $PATH' — verify the directory containing the command is listed
  2. 2Add to PATH permanently: add 'export PATH="$HOME/.local/bin:$PATH"' to ~/.bashrc (Bash) or ~/.zshrc (Zsh)
  3. 3Apply changes immediately: 'source ~/.bashrc' or start a new terminal session
  4. 4For systemd services: add Environment= or EnvironmentFile= to the [Service] section of the unit file
  5. 5Debug shell startup: 'bash -x -l -c exit 2>&1 | head -50' to trace which files are loaded

Tags

environmentpathbashrcprofileshell

More in System

Frequently 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.