How can I reload file .bash_profile from the command line?
I can get the shell to recognize changes to .bash_profile by exiting and logging back in, but I would like to be able to do it on demand.
How can I reload file .bash_profile from the command line?
I can get the shell to recognize changes to .bash_profile by exiting and logging back in, but I would like to be able to do it on demand.
Simply type source ~/.bash_profile
.
Alternatively, if you like saving keystrokes, you can type . ~/.bash_profile
.
alias reload='source ~/.bash_profile && echo "File .bash_profile reloaded correctly" || echo "Syntax error, could not import the file"';
–
Nature .bash_profile
? –
Hexone ~/.bash_history
as the filename. –
Wildman source ~/.zprofile
? –
Goldner . ~/.bash_profile
Just make sure you don't have any dependencies on the current state in there.
.
command in this case? –
Suite .
is simply an alias for the source
command. –
Viscountess .
is older than source
is. –
Ronnironnica source
is a bash specific implementation of .
–
Ratepayer .
is an alias or is source
a specific implementation? –
Anabantid .
and source
are literally the same thing in bash. From the link: "source
is a synonym for dot/period '.
' in bash, but not in POSIX sh, so for maximum compatibility use the period." –
Ronnironnica Simply type:
. ~/.bash_profile
However, if you want to source it to run automatically when terminal starts instead of running it every time you open terminal, you might add . ~/.bash_profile
to ~/.bashrc
file.
Note:
When you open a terminal, the terminal starts bash in (non-login) interactive mode, which means it will source ~/.bashrc
.
~/.bash_profile
is only sourced by bash when started in interactive login mode. That is typically only when you login at the console (Ctrl+Alt+F1..F6), or connecting via ssh
.
If you don't mind losing the history of your current shell terminal, you could also do
bash -l
That would fork your shell and open up another child process of bash. The -l
parameter tells Bash to run as a login shell. This is required, because .bash_profile will not run as a non-login shell. For more information about this, read here.
If you want to completely replace the current shell, you can also do:
exec bash -l
The above will not fork your current shell, but replace it completely, so when you type exit
it will completely terminate, rather than dropping you to the previous shell.
You can also use this command to reload the ~/.bash_profile for that user. Make sure to use the dash.
su - username
I like the fact that after you have just edited the file, all you need to do is type:
. !$
This sources the file you had just edited in history. See What is bang dollar in bash.
.
" is an alias for "source
". On the man page it is near "in the current shell environment and return the exit status of the last command executed from" (though not that helpful (too terse)). –
K You just need to type . ~/.bash_profile
.
Refer to What does 'source' do?.
cd
. .bash_profile
cd
. No need for ~
. –
Irresolution cd
- you can just reload it from the directory you're currently in: . ~/.bash_profile
–
Ked If the .bash_profile file does not exist, you can try to run the following command:
. ~/.bashrc
or
source ~/.bashrc
instead of .bash_profile.
You can find more information about bashrc.
Add alias bashs="source ~/.bash_profile"
into your Bash file.
So you can call bashs
the next time.
reset
-- easier to remember –
Cobby Use
alias reload!=". ~/.bash_profile"
Or if want to add logs via functions:
function reload! () {
echo "Reloading bash profile...!"
source ~/.bash_profile
echo "Reloaded!!!"
}
. ~/. bash_profile
nor source ~/.bash_profile
–
Buonarroti While using source ~/.bash_profile
or the previous answers works, one thing to mention is that this only reloads your Bash profile in the current tab or session you are viewing. If you wish to reload your bash profile on every tab/shell, you need to enter this command manually in each of them.
If you use iTerm, you can use CMD⌘ + Shift + I to enter a command into all current tabs. For terminal it may be useful to reference this issue;
I use Debian and I can simply type exec bash
to achieve this. I can't say if it will work on all other distributions.
. .bash_profile
while inside your home directory on Mac will do the job. Same as the reply given above by 7urkm3n. –
Panarabism I am running macOS v10.12 (Sierra) and was working on this for a while (trying all recommended solutions). I became confounded, so I eventually tried restarting my computer! It worked.
My conclusion is that sometimes a hard reset is necessary.
Simply re-sourcing the file won't "reload" in the sense that something is first unloaded, then loaded again. If that is what you want you can do:
hash -r && _SHOW_MESSAGES=1 exec -a -bash bash
© 2022 - 2024 — McMap. All rights reserved.
alias BASHRELOAD=". ~/.bash_profile"
. If you do this often you can just alias it asbr
. – Baa