120

Is it possible to coerce bash to reload the .profile file without logging out and back in again?

1
  • Have you tried to use /etc/profile.d/ scripts? Create the script there, and open a non-login terminal. That runs each time you launch terminal and persists even after you quit terminal.
    – WesternGun
    Oct 25, 2023 at 8:18

2 Answers 2

161

This should work for the current terminal:

. ~/.profile

. is a bash builtin and a synonym for source, see man bash:

. filename [arguments]
source filename [arguments]
     Read and execute commands from filename in the current shell environment (…).

8
  • 30
    It will be effective only in the current terminal.
    – enzotib
    Aug 29, 2011 at 14:14
  • 2
    @enzotib Is there a way to work around that?
    – Matty
    Aug 29, 2011 at 14:20
  • 17
    @Matty: no, to make the changes visible to the whole graphical environment, you can only restart the session
    – enzotib
    Aug 29, 2011 at 14:22
  • 4
    The only issue with this is if you remove something from path it would not take effect until you restart
    – Aras
    Sep 12, 2016 at 19:44
  • 5
    @Aras makes an IMPORTANT POINT that deserves expansion: If something is removed from ~/.profile, that change will not take effect after . ~/.profile reload. For example, add a function to ~/.profile: function externalip () { curl http://ipecho.net/plain; echo; }, then ~/.profile - IT WORKS. Now remove that function from ~/.profile, then . ~/.profile again. The function is still available - only restarting (log out & in) will remove it.
    – Seamus
    Mar 26, 2019 at 1:17
16

If you don't want to start a new shell but execute the script in the current shell, you source it:

source script_name.sh

source = .

The Bash source built-in is a synonym for the Bourne shell . (dot) command.

courtesy - tldp.org

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .