Diagnose why an environment variable is missing in new shells, then make it persist correctly across terminal sessions. Validate the change using repeatable CLI checks and evidence in shell config files.
A developer reports that the PROJECT_ROOT
environment variable does not persist across terminal sessions.
Your task is to confirm the issue, determine where it should
be defined, and ensure it loads automatically in all new
sessions.
“Works in my current terminal” is not good enough. You need persistence across fresh shells and evidence that the export line is present in the right startup file.
PROJECT_ROOT is currently set.~/.bashrc.~/.bashrc as evidence.printenv and env.
grep.
~/.bashrc safely.
source.
PROJECT_ROOT is set in the current session.
printenv PROJECT_ROOT
# OR
env | grep PROJECT_ROOT
This confirms whether the variable exists in the current environment. If it disappears after opening a new terminal, it is almost always a shell init file issue, not a “Linux is broken” issue.
/home/dev/project
# OR
PROJECT_ROOT=/home/dev/project
PROJECT_ROOT is defined in ~/.bashrc.
grep PROJECT_ROOT ~/.bashrc
~/.bashrc is a common place for user-level exports
that must load in interactive shells. If the export line is
missing, the variable will not persist.
# No output means the variable is not set in ~/.bashrc
echo 'export PROJECT_ROOT=/home/dev/project' >> ~/.bashrc
Appending the export line makes it load automatically for
future interactive shells that read ~/.bashrc.
source ~/.bashrc
Reloading applies the change to the current terminal without needing to close and reopen the session.
printenv PROJECT_ROOT
# OR
env | grep PROJECT_ROOT
/home/dev/project
# OR
PROJECT_ROOT=/home/dev/project
This confirms the export is live in the current environment. For true persistence, open a new terminal and re-run the same check.
~/.bashrc.
grep PROJECT_ROOT ~/.bashrc
export PROJECT_ROOT=/home/dev/project
This is your evidence that the fix is persistent and repeatable, not a one-time environment accident.
printenv VAR
: Prints the value of an environment variable if it is set.
env
: Lists environment variables for the current process.
grep PATTERN FILE
: Searches for matching lines (used here to audit startup files).
~/.bashrc
: Common startup file for interactive Bash shells.
source FILE
: Loads a file into the current shell session without restarting.