Is it possible to coerce bash to reload the .profile file without logging out and back in again?
Asked
Active
Viewed 1.8e+01k times
2 Answers
162
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 (…).

dessert
- 39,982

Lukas Stejskal
- 1,857
-
30
-
2
-
17@Matty: no, to make the changes visible to the whole graphical environment, you can only restart the session – enzotib Aug 29 '11 at 14:22
-
4The only issue with this is if you remove something from path it would not take effect until you restart – Aras Sep 12 '16 at 19:44
-
@enzotib Is it effective for all sub processes started from current terminal? – Bruce Sun Aug 04 '17 at 02:39
-
-
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 '19 at 01:17 -
@enzotib You could theoretically reprogram your window manager to allow it extract the new environment variables from
~/.profile
, which would allow any newly started programs to use the new environment variables without having to restart your entire X11 session, but because of the UNIX design, running processes, as well as programs started by running processes will still need to be restarted to receive the new environment.It's probably not worth to implement such a feature for something you only do very rarely (Updating
– yyny Jul 18 '20 at 14:17~/.profile
), though.
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.
/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 '23 at 08:18