How to reload .bashrc settings without logging out and back in again?

To reload your .bashrc file (or any shell configuration file) without logging out and back in, use the source command or its shorthand equivalent . (dot). This re-executes the .bashrc file in your current shell session, applying any changes immediately.

Command:

source ~/.bashrc
# or equivalently
. ~/.bashrc

Example Workflow:

  1. Edit your .bashrc (e.g., add an alias or update PATH):
   echo 'alias ll="ls -alh"' >> ~/.bashrc
  1. Reload the changes:
   source ~/.bashrc
  1. Verify (e.g., test the new alias):
   ll  # Outputs detailed directory listing

Why This Works:

  • The source command runs the .bashrc script in the current shell environment, updating variables, aliases, and functions.
  • Without source, changes to .bashrc only take effect in new terminal sessions.

Key Notes:

  • Scope: Only affects the current terminal session. Other open terminals remain unchanged unless you reload them individually.
  • Syntax Errors: If .bashrc has errors, source may fail partially or entirely. Check for issues with:
  bash -n ~/.bashrc  # Syntax check without executing
  • Other Files: Use the same method for .bash_profile, .zshrc, etc.:
  source ~/.bash_profile

Use source to instantly apply configuration changes!

Leave a Reply

Your email address will not be published. Required fields are marked *