How do I permanently set my bashrc changes?
Solution 1:
There is the ~/.profile
(or ~/.bash-profile
) file, that runs at every login. You should set environment variables there (with the export
command). And there is the ~/.bashrc
file, which is run on opening each sell. Commands that are not inherited to all subshells, like alias, can be set here (though for good practise, aliases should be set in ~/.aliases
, which is automatically sourced by ~/.bashrc
).
If it doesn't work for you, you either use a wrong filename (missing "." from beginning?), or you don't use bash as your shell. In the latter case, try passwd -s /bin/bash
(or chsh -s /bin/bash
, depending on OS), or call the SSH the following way:
ssh username@host bash`
Solution 2:
You should also know about $BASH_ENV .
What files are read by bash when it starts up depends on if the session is interactive or not. Occasionally there can be an issue where it's not clear if the session is interactive. So besides ~/.bashrc you might want to also export and set variable BASH_ENV to point to a file containing the PATH and other settings that you need. BASH_ENV can be set to point to your .bashrc file (sometimes it's .bash_rc) so long as there are no interactive commands in there (to be safe use a separate file, say ~/.bash_env). From the bash man pages:
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.
When bash is started non-interactively, to run a shell script, for example, it looks for the variable BASH_ENV in the environment, expands its value if it appears there, and uses the expanded value as the name of a file to read and execute. Bash behaves as if the following command were executed:
if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
but the value of the PATH variable is not used to search for the file name.
Solution 3:
I know this is old, but i think on a new login shell, bash looks for a single file to run. It looks for .bash_profile, then .profile, then .bashrc. If it finds .bash_profile or .profile, it won't further look for .bashrc.
Solution, put in your .profile:
[ -f $HOME/.bashrc ] && . $HOME/.bashrc
Solution 4:
There are already several (probably correct) answers but I had this exact same problem and this is what worked for me:
add to ~/.bash_profile
the following lines:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
See here and here for more info.
(note, in my $HOME directory I already had the following files:
.bash_aliases
.bash_history
.bash_logout
.bash_profile
.bashrc
)