If I make changes to .bashrc, how do I reload it without logging out and back in?
.bashrc
You can enter the long form command:
source ~/.bashrc
or you can use the shorter version of the command:
. ~/.bashrc
This is not exactly the same as logging in and back out. Say you had the following line in .bashrc:
export PATH=$PATH:foo
, and then you change it toexport PATH=$PATH:bar
. If you log in and back out, onlybar
will be in the PATH, but if you do what you suggest, bothfoo
andbar
will be in the PATH. Do you know of a way around this?@HighCommander4 - a very unsatisfactory way to sort of do what you want is to do "bash -l" however this actually creates a new subshell and when you logout you'll return to the enclosing shell where "foo" is still in PATH. If you're just interested in PATH, you could do "unset PATH" and reconstruct it from scratch, but probably easier/safer is to do "PATH=/bin:/usr/bin" before sourcing your .bashrc. How the PATH variable is built up on login is actually reasonably complex, involving input at the very least from login (see "man login") and /etc/profile (see "man bash").
@Alex you can automate it by adding the line ~/.bashrc into ~/.bash_profile, though I don't know if this is a good practice.
I would also recommend creating an alias (which you could store in ~/.bashrc or ~/.bash_aliases) that opens .bashrc, and reloads it after the editor exits. You can do it by combining two commands in an alias, for example like so (if vim is your preferred editor, otherwise swap it out to something else):
alias editbashrc='vim ~/.bashrc; source ~/.bashrc'
. This will make the editing much smoother, since you don't need to think about the reloading, after doing the edit, if using the custom alias.It will affect only the current terminal.