As indicated by /etc/bashrc and /etc/profile, create custom.sh in /etc/profile.d/ by executing
touch /etc/profile.d/custom.sh
and
chmod +x /etc/profile.d/custom.sh
This file is not a sytem file such as /etc/bashrc, but customed (hence the name) to the user such as ~/.bashrc.
Enter into this file the following (not my actual file, just a demonstration)
> if shopt -q login_shell; then
> printf '%s %s\n %s\n' 'Loading /etc/profile.d/custom.sh'\
> '(See /etc/bashrc or /etc/profile)...'\
> 'Invoking interactive login shell...'
> if [ "$TERM" = "linux" ]; then
> printf '%b %s%b\n' "\E[32mHi $USER from Virtual Console" `tty` "\E[0m"
> fi
> printf '%s:\n' 'Set following ENV variable(s)'
> printf ' %s\n' '1. SAMPLE_VAR1'
> SAMPLE_VAR1="From file /etc/profile.d/custom.sh, a sample variable."
> else
> printf '%s %s\n %s\n' 'Loading /etc/profile.d/custom.sh'\
> '(See /etc/bashrc or /etc/profile)...'\
> 'Invoking interactive non-login shell...'
> printf '%s:\n' 'Set following ENV variable(s)'
> printf '%s\n' '1. SAMPLE_VAR2'
> SAMPLE_VAR2="From file /etc/profile.d/custom.sh, a sample variable."
> if my_bin=$(echo $PATH | grep "$HOME/bin"); then
> printf '%s\n' "Path to \"${my_bin##*:}\" already set."
> else
> PATH=$PATH:$HOME/bin
> fi
> fi
Into the files
- /etc/bashrc (system; interactive non-login; functions and aliases)
- /etc/profile (system; interactive login; environment variables)
- ~/.bashrc (user; interactive non-login; functions and aliases)
- ~/.bash_profile (user; interactive login; environment variables)
enter, for example,
"# My Section"
"printf '%s\n' 'Loading /etc/bashrc...'"
"# Done My Section"
Now
- CTRL+ALT+F3 for text mode (Virtual Console)
- Open new terminal in graphical mode thereby starting a new bash session (pseudo-terminal)
- In the pseudo-terminal, enter su - (Super-user: if you have the privelege)
Caveat: don't put environment variables into ~/.bashrc; use custom.sh.
Do not edit global system files - use
~/.bashrc
instead: https://ask.fedoraproject.org/en/question/35168/cant-login-in-fedora-after-switching-from-openjdk-to-oracle-java/ . The answer to you question is provided at https://ask.fedoraproject.org/en/question/24028/how-to-set-environment-variable-permanet/So, how do i set a permanent change to PATH?
If you want to change the PATH env var for just one user, revert the changes you did in /etc/profile and instead edit ~/.bash_profile.
By default you should find these two lines in ~/.bash_profile:
for example in this case $HOME/bin is added to the PATH env var. Note that you'll need to log out / log in for the changes to take effect in bash sessions (or you can
source ~/.bash_profile
manually until you log out / log in).Thanks for your answer, but i think i don't have this file. Anyway, not in /ect and not in / And, i would like to set the PATH env var to all users.
@Ahmad Samir - looks like you have all the info for a very thorough answer!