By markdorison

2011-01-05 19:09:07 8 Comments

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.


@Ulukai 2018-10-23 08:42:45

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.

@Xitcod13 2019-05-31 17:38:23

you wont loose your history if you're using iterm2

@Jenil Mewada 2018-08-18 07:34:54

you just need to type . ~/.bash_profile


@7urkm3n 2018-02-06 11:47:57

alias reload!=". ~/.bash_profile"

or if wanna add logs via functions

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

@7urkm3n 2018-03-30 18:06:30

No, its on yr preference. If wanna add some extra print lines showing status nor just go simply . ~/. bash_profile nor source ~/.bash_profile

@aug 2017-05-19 21:14:55

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;

@hyper_st8 2016-11-08 14:45:29

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.

@3pitt 2017-04-26 15:13:15

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

@Cassandra 2017-05-02 06:56:22

Mike yes a hard reset will work because everything is then loaded freshly. As long as the changes you have made are functional, it will then take effect on next boot up. However it would be easier for you to dig around a little to find the command/method to just refresh the bash without having to do that all the time. There will be a way to achieve it without the reboot, which of course will soak up way too much time just to see if the latest change works! Perhaps have a look at…

@3pitt 2017-05-02 16:50:58

yeah i tried both the abbreviated and full command to reload bash profile/path. it didn't work, only logging out and back in worked. weird

@Cassandra 2017-03-29 02:50:03

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.

@Ulukai 2018-10-23 08:47:40

This will not work in Mac (at least not in the version I am using - Sierra) because simply doing that executes a no login shell which does not run the .bash_profile

@Cassandra 2018-10-25 00:00:53

@Ulukai apparently just typing . .bash_profile while inside your home directory on Mac will do the job. Same as the reply given above by 7urkm3n.

@Ezequiel De Simone 2016-08-12 19:22:16

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

. ~/.bashrc 


 source ~/.bashrc

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

@Mithun Khatri 2014-05-07 10:15:32

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

@roNn23 2015-04-10 12:26:55

Just go to home with cd. No need for ~.

@Alex Villa 2015-09-02 21:17:58

No need to cd - you can just reload it from the directory you're currently in: . ~/.bash_profile

@Shemeer M Ali 2015-09-10 13:12:37

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

@jcollum 2016-07-05 20:01:17

I alias that to reset -- easier to remember

@Mohammad Anini 2015-05-10 19:44:53

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.


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.

@user1003932 2012-09-19 23:33:38

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

su - username

@underscore_d 2015-09-24 00:37:26

This will invoke an entire shell within a shell, far from ideal. The other options simply re-execute the relevant file, meaning they're (A) actually relevant to the asked question and (B) not piling up shells and possibly reloading other things that shouldn't be (env vars, etc.). There are proper ways to replace the current shell outright (without nesting), but since that's off-topic, I'll leave interested readers to search elsewhere.

@Juan Diego 2015-11-09 17:23:47

you are opening another shell, this is not a reload you might as well open a new terminal or re log

@Carl Norum 2011-01-05 19:11:30

. ~/.bash_profile

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

@Jonah 2014-07-02 11:26:42

Why does this work? Ie, what is the . command in this case?

@Graham P Heath 2014-10-31 15:07:06

the dot operator: . is simply an alias for the source command.

@Carl Norum 2014-10-31 15:53:08

@GrahamPHeath - strictly speaking I think it's the other way around; the . is older than source is.

@Thirupathi Thangavel 2015-11-30 07:15:17

source is a bash specific implementation of .

@Johnny 2017-01-15 11:30:44

So, . is an alias or is source a specific implementation?

@Carl Norum 2017-01-15 16:31:23

@StasS - . 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."

@jgmjgm 2019-02-27 19:34:19

This method isn't guaranteed to work or to be clean because .bash_profile is not guaranteed to be idempotent. For a cleaner method then you really want to start a new bash process.

@SiegeX 2011-01-05 19:10:03

Simply type source ~/.bash_profile

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

@bobobobo 2013-04-22 18:56:16

How about alias BASHRELOAD=". ~/.bash_profile". If you do this often you can just alias it as br.

@erwinheiser 2014-09-13 13:22:57

any reason why I'd need to do this every single time/session? I can't get changes made to .bash_profile to persist even though they're there in the file when I open it in an editor. Confusing.

@Graham P Heath 2014-10-31 15:01:17

@erwinheiser is your system loading the file? Some systems use other files, such as ~/.bashrc.

@Cristian Batista 2018-02-08 08:19:48

If you want to know if something went wrong on the load you can use: alias reload='source ~/.bash_profile && echo "File .bash_profile reloaded correctly" || echo "Syntax error, could not import the file"';

@jxramos 2019-09-04 22:25:20

That's a really surprising metacharacter usage. What's the context where it is interpreted as source? I'm used to thinking of that as the current directory character. Is this a role it plays particularly in the global context of the .bash_profile?

@Sankofa 2019-12-09 21:29:53

For people who forgot that you switched over to OhMyZsh. run open ~/.zshrc and make the changes there instead of your .bash_profile

@JiK 2020-02-25 22:48:43

Pro-tip: Do not accidentally run this with ~/.bash_history as the filename.

@John 2020-08-28 15:46:27

This adds duplicates in my path. Isn't that an issue?

Related Questions

Sponsored Content

49 Answered Questions

[SOLVED] How do I import an SQL file using the command line in MySQL?

14 Answered Questions

[SOLVED] How do I set a variable to the output of a command in Bash?

62 Answered Questions

[SOLVED] How to call an external command?

26 Answered Questions

[SOLVED] Is there an equivalent of 'which' on the Windows command line?

18 Answered Questions

[SOLVED] In the shell, what does " 2>&1 " mean?

  • 2009-05-03 22:57:00
  • Tristan Havelick
  • 1158284 View
  • 2375 Score
  • 18 Answer
  • Tags:   bash shell unix redirect

67 Answered Questions

[SOLVED] How to get the source directory of a Bash script from within the script itself?

  • 2008-09-12 20:39:56
  • Jiaaro
  • 1791283 View
  • 5110 Score
  • 67 Answer
  • Tags:   bash directory

13 Answered Questions

[SOLVED] How to echo shell commands as they are executed

20 Answered Questions

[SOLVED] How to call shell commands from Ruby

  • 2008-08-05 12:56:52
  • CodingWithoutComments
  • 539214 View
  • 1105 Score
  • 20 Answer
  • Tags:   ruby shell interop

17 Answered Questions

[SOLVED] How do I reload .bashrc without logging out and back in?

Sponsored Content