My Emacs build broke at 2 a.m. because of a single missing environment variable.
If you use Emacs for serious work, you already know how one wrong $PATH, unset LANG, or rogue PYTHONPATH can turn a calm day into a debugging spiral. Environment variables quietly govern how Emacs talks to your shell, your compiler, and your project dependencies. They define what Emacs can find, run, and load—both inside your editor and in every subprocess it spawns.
Why Emacs Environment Variables Matter
Emacs does not always inherit the same environment variables your shell session uses. On some systems, the GUI version starts without sourcing shell config files. This means commands in M-x shell, eshell, or compilation-mode might fail, even though they work fine in your terminal. The way Emacs handles these variables can change across OSes, desktop environments, and even window managers.
Common Problems and Their Fixes
Missing $PATH: If Emacs cannot find your executables, check the value of exec-path inside Emacs. Sync it with your shell by adding something like this to your config:
(setq exec-path (append exec-path '("/usr/local/bin")))
(setenv "PATH"(concat "/usr/local/bin:"(getenv "PATH")))
Incorrect locale settings (LANG, LC_ALL): If you see strange encoding issues, set them directly in your init file: