BASH Programming

How to Reload bashrc in Bash

Bash is a UNIX shell and command language that you’ll find on almost all Linux distros. First released in 1989 by Brian Fox, Bash has been the default shell for most Linux distros. The name “Bash” is actually an acronym for “Bourne Again Shell”, an intended pun of the Bourne shell it replaces.

In this guide, we’ll have a quick look at bashrc and how to reload it after making any changes.

The bashrc Script

The bashrc is a shell script for the Bash shell. Bash will run the commands within bashrc every time it runs. It’s basically a shell script to initiate a shell session.

The bashrc file can contain a variety of codes and commands. For example, you can set JAVA_HOME (for working with Java apps), use bash aliases to create your own custom command, manage Bash environment variables like PATH, etc. You can also use bashrc to colorize your console output!

The file is located at the following location.

$ ~/.bashrc

As the location suggests, the bashrc file is unique for each user. Making changes won’t affect anyone on the system. However, there are other scripts that Bash loads during startup. For example, bash_profile.

There are various types of bashrc files present throughout the system.

  • /etc/skel/.bashrc: This file provides the default copy for every new user in the system.
  • /home/<username>/.bashrc: This is the user-specific file that will be loaded each time the user starts a bash session.
  • /root/.bashrc: It’s dedicated to the root user. Whenever root opens the shell, it will be used.

Why Reload bashrc

When a Bash shell session is launched, it reads all the associated configurations and scripts. After that, Bash doesn’t read them again (unless commanded to). This is why you’ll be recommended to restart the Bash session to take the bashrc changes into effect.

Editing bashrc

The bashrc file is a text file containing Bash commands. You can use any text editor to edit this file. For example, we can use nano or vim for editing on the console UI.

$ nano ~/.bashrc

$ vim ~/.bashrc

Reloading bashrc

After you’ve made changes, save the file and close the text editor. As mentioned earlier, Bash doesn’t check for bashrc changes after the session starts. Running the following command will tell Bash to reload bashrc:

$ source ~/.bashrc

The key here is the source command. It’s an integral shell instruction. It tells the shell to load (read and execute, basically) commands from the file specified. Remember that bashrc is a bash script. With this command, Bash re-runs the script. All the changes made are applied automatically.

Here’s a more in-depth guide on using the Linux source command with examples.

Final Thoughts

This guide successfully demonstrates reloading the bashrc file. Bash comes with the source command for this purpose. It loads all the shell commands of the file specified into the current Bash session. Bash will load the updated bashrc file automatically next time it starts.

Bash is also a robust scripting language that can automate a lot of tasks in the Linux environment. Interested in beginning your journey with Bash scripting? Check out this guide on Bash programming syntaxes and variables.

Happy computing!

About the author

Sidratul Muntaha

Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.