Skip to main content
How To

How to Open and Edit bashrc file in Ubuntu

New to Ubuntu and wondering how to edit the bashrc file? Here's how to do that.

Sagar Sharma

While customizing your Linux terminal, you will come across a term called .bashrc file but if you are new to Linux, you may not know what it is and how to access it.

Well, if you don't want to get into further details and just want to open it, execute this command:

nano ~/.bashrc

Make the changes and quit it by pressing Ctrl+X.

But if you want to learn more about the bashrc file and some basics to edit it, then be my guest and let this guide serve you.

Open the bashrc file in Ubuntu

The bashrc file is short for Bourne Again SHell Run Commands and is available in the bash shell operating systems (yes, Ubuntu uses bash by default).

The thing is every time you open a new bash shell, the bashrc file is used to define various configuration settings, aliases, functions, and other customizations.

Now you know the reason why every guide on the internet has instructions to make changes in the bashrc file for terminal customizations.

At the beginning of this guide, I explained how you can open the bashrc file in Ubuntu but it uses the nano text editor and some of you may want to use a different text editor.

For that purpose, you can define your favorite text editor in the following manner:

<text_editor> ~/.bashrc

For example, if you want to use the gedit, then use the following:

gedit ~/.bashrc

But just accessing the bashrc file won't do it so let me share some basic editing that you can do with the bashrc file.

Edit the bashrc file

📋
I'm assuming you are using the nano text editor to edit the bashrc file.

There are basic things that you need to know while editing the bashrc file and opening the bashrc file was already explained.

I always recommend writing new lines at the end of the file as you can easily reach out to a part where all the manual changes were done and can be changed easily.

To go to the end of the file in the nano text editor, press Alt + /:

go to the end of the file in bashrc file

You can always use the hashtags # to comment out the lines that you don't want to be effective in the bashrc file or you can use it to explain the purpose of the line.

For example, here, I used the hashtag to write a comment explaining that alias:

using comments in bashrc file
💡
You will also find some lines that start with # and to use them, simply remove the hashtag.

if you want to search and replace words in bashrc, then here's a detailed guide explaining how you do it:

Search and Replace in the Nano Text Editor
Look for a specific string or replace it with something else. Here’s how to search and replace in Nano.

Once you make the appropriate changes, to save and exit from the bashrc file, press Ctrl + O, hit Enter and then Ctrl + X:

save changes and exit from the bashrc file

But that won't do it! To take effect from the changes you've just made, you have to source the bashrc file as shown:

source ~/.bashrc

That will do it.

Want more customization? Use zsh

If you feel bash does not have to offer customization, then you can use the zsh, a modern shell that provides various customization options.

Here's a detailed guide explaining how you use the zsh to theme your terminal:

Install and Setup ZSH on Ubuntu Linux
Want a cool looking Linux terminal? Try Zsh. Learn how to set up Zsh on Ubuntu Linux with Oh My Zsh.

I hope you will find this guide helpful.

Sagar Sharma