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.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/02/echo/word-image-879.png" data-lazy- height="127" src="data:image/svg xml,” width=”1213″>

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//.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.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/02/echo/word-image-885.png" data-lazy- height="696" src="data:image/svg xml,” width=”1211″>

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/02/echo/word-image-890.png" data-lazy- height="697" src="data:image/svg xml,” width=”1210″>

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:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/02/echo/word-image-895.png" data-lazy- height="100" src="data:image/svg xml,” width=”1210″>

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

<img data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2022/02/echo/profile-photo-1-150×150.jpg621700dd0d923.jpg" height="112" src="data:image/svg xml,” width=”112″>

Sidratul Muntaha

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