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