Set a common environment variable for all users of login shells.
Do not place the setting in an individual home directory.
Which is the standard location?
/etc/profile is the system-wide initialization file for login shells. It has a broader scope than user-specific startup files.
Detailed explanation
/etc/profileCorrect. /etc/profile is used for system-wide login-shell initialization.
Correct. /etc/profile is used for system-wide login-shell initialization.
~/.bash_profileIncorrect. ~/.bash_profile is specific to one user's Bash login shell.
Incorrect. ~/.bash_profile is specific to one user's Bash login shell.
~/.bashrcIncorrect. ~/.bashrc is a per-user interactive Bash configuration file.
Incorrect. ~/.bashrc is a per-user interactive Bash configuration file.
~/.bash_logoutIncorrect. ~/.bash_logout runs when a login Bash exits.
Incorrect. ~/.bash_logout runs when a login Bash exits.
Try it yourself
An example you can run in a temporary verification environment.
test -r /etc/profile && sed -n '1,8p' /etc/profileExpected result
/etc/profileの先頭部分。内容は環境により異なるKey points
- /etc/profile is system-wide
- It is processed at login
- It applies more broadly than user files
Notes
- Environment: GNU Bashを利用するLinux / 読み取りのみ
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.