Inspect the current shell environment, set variables for the active session, and make changes persist across login shells. Update PATH safely and identify the correct per-user and system-wide startup locations.
A teammate reports that a tool works in one terminal session but “disappears” in a new login. You need to validate the current environment, export variables correctly, and make changes persist for bash login shells without breaking existing PATH behavior. You also need to know where to place global environment settings for all users.
Most “it works on my machine” issues in Linux come down to startup files, PATH ordering, and whether the shell is login vs non-login. Treat env changes like config changes: verify, apply, re-check in a new session.
printenv and env.
~/.bash_profile, ~/.bash_login, ~/.profile).
export PATH="$PATH:/new/path".
/etc/environment.
printenv
# OR
env
Both printenv and env display the exported environment for the current process context.
This is the fastest way to confirm what the shell will pass to child processes.
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOME=/home/lab
SHELL=/bin/bash
export FOO=bar
export marks the variable for inheritance by child processes.
Without export, the variable exists only as a shell variable in the current shell.
Variable FOO set to 'bar'.
~/.bash_profile
# OR (depending on system config)
~/.bash_login
~/.profile
bash login shells typically read ~/.bash_profile first. If it does not exist, bash may fall back to
~/.bash_login or ~/.profile depending on how the system is configured.
Adding export FOO=bar there makes it available in new login sessions.
# Add a line like:
export FOO=bar
/opt/scripts to PATH for this session.
export PATH=$PATH:/opt/scripts
Always preserve the existing PATH by referencing $PATH. Appending adds your directory at the end, which reduces the risk of
accidentally shadowing system binaries with a custom script of the same name.
PATH updated for this session.
/etc/environment
/etc/environment is commonly used to define global environment variables at login for all users.
It is not a shell script. Keep the format simple (KEY=VALUE) and avoid shell syntax.
/etc/environment is used for global env vars.
# Start a new login shell and confirm:
printenv FOO
echo $PATH
Session changes prove the syntax works. A new login session proves persistence and correct startup-file placement. This is the standard “done means verified” check for environment troubleshooting.
# Expected:
bar
# PATH should include:
/opt/scripts
printenv
: Displays exported environment variables.
env
: Displays the environment and can run a command with a modified environment.
export NAME=value
: Creates or updates an environment variable for the current shell and its child processes.
~/.bash_profile, ~/.bash_login, ~/.profile
: Per-user startup files typically read by bash login shells (selection depends on what exists and system config).
/etc/environment
: System-wide environment variables for all users at login (KEY=VALUE format, not shell code).
PATH
: Controls command lookup order; preserve existing values when modifying ($PATH).