How to reload .bash_profile from the command line?

BashShellCommand Line

Bash Problem Overview


> How can I reload .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.

Bash Solutions


Solution 1 - Bash

Simply type source ~/.bash_profile

Alternatively, if you like saving keystrokes you can type . ~/.bash_profile

Solution 2 - Bash

. ~/.bash_profile

Just make sure you don't have any dependencies on the current state in there.

Solution 3 - Bash

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.

Solution 4 - Bash

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 info 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.

Solution 5 - Bash

You can also use this command to reload the ~/.bash_profile for that user. Make sure to use the dash.

su - username

Solution 6 - Bash

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.

Solution 7 - Bash

  1. Save .bash_profile file
  2. Goto user's home directory by typing cd
  3. Reload the profile with . .bash_profile

Solution 8 - Bash

you just need to type . ~/.bash_profile

refer: https://superuser.com/questions/46139/what-does-source-do

Solution 9 - Bash

Add alias bashs="source ~/.bash_profile" in to your bash file. So you can call bashs from next time

Solution 10 - Bash

alias reload!=". ~/.bash_profile"

or if wanna add logs via functions

function reload! () {
	echo "Reloading bash profile...!"
	source ~/.bash_profile
	echo "Reloaded!!!"
}

Solution 11 - Bash

if the .bash_profile does not exist you can try run the following command:

. ~/.bashrc 

or

 source ~/.bashrc

instead of .bash_profile. You can find more information about bashrc

Solution 12 - Bash

I wanted to post a quick answer that while using source ~/.bash_profile or the answers mentioned above 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;

Solution 13 - Bash

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.

Solution 14 - Bash

I am running Sierra, and was working on this for a while (trying all recommended solutions). I became confounded so eventually tried restarting my computer! It worked

my conclusion is that sometimes a hard reset is necessary

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmarkdorisonView Question on Stackoverflow
Solution 1 - BashSiegeXView Answer on Stackoverflow
Solution 2 - BashCarl NorumView Answer on Stackoverflow
Solution 3 - BashMohammad AniniView Answer on Stackoverflow
Solution 4 - BashUlukaiView Answer on Stackoverflow
Solution 5 - Bashuser1003932View Answer on Stackoverflow
Solution 6 - Bashhyper_st8View Answer on Stackoverflow
Solution 7 - BashMithun KhatriView Answer on Stackoverflow
Solution 8 - BashJenil MewadaView Answer on Stackoverflow
Solution 9 - BashShemeer M AliView Answer on Stackoverflow
Solution 10 - Bash7urkm3nView Answer on Stackoverflow
Solution 11 - BashEzequiel De SimoneView Answer on Stackoverflow
Solution 12 - BashaugView Answer on Stackoverflow
Solution 13 - BashCassandraView Answer on Stackoverflow
Solution 14 - Bash3pittView Answer on Stackoverflow