# How to Add Paths to Bashrc Effortlessly

Have you ever been frustrated by not being able to access certain programs or files on your Linux system because the system couldn't find them?

This issue often arises when the system is unable to locate the executable files or scripts you want to run, and it's because their locations are not included in the system's PATH variable.

Fortunately, there's a straightforward solution to this problem: adding the relevant paths to the PATH variable in your .bashrc file.

In this article, we'll explain what the PATH variable is, why it's important, and how you can add new paths to it by modifying your .bashrc file. By the end, you'll be able to easily access your programs and scripts from anywhere on your system.

## Understanding the PATH Variable

The PATH variable is a list of directories where the shell looks for executable files and scripts when you type a command. When you enter a command in the terminal, the shell searches through the directories listed in the PATH variable in a specific order until it finds the executable file or script you're trying to run.

If the file or script you're looking for isn't located in any of the directories listed in the PATH variable, the shell will inform you that the command or program couldn't be found.

## The .bashrc File

The .bashrc file is a script that runs every time you open a new terminal session or window. It's a way to customize your Bash shell environment and set up various preferences and settings.

One of the most common uses of the .bashrc file is to modify the PATH variable by adding or removing directories from the list of locations where the shell searches for executable files and scripts.

## Adding a New Path to the PATH Variable

To add a new path to the PATH variable, you need to edit your .bashrc file. Here are the steps:

1. Open your terminal.
    
2. Use a text editor to open the .bashrc file. You can do this by entering the following command: `nano ~/.bashrc`
    
3. In the text editor, scroll down to the end of the file.
    
4. Add the following line, replacing `/path/to/your/directory` with the actual path you want to add: `export PATH="$PATH:/path/to/your/directory"`
    
5. Save and exit the file.
    
6. To apply the changes, either log out and log back in or run the following command: `source ~/.bashrc`
    

After following these steps, the new path will be added to the PATH variable, and the shell will search for executable files and scripts in that directory whenever you enter a command.

### Example: Adding a Custom Script Directory

Let's say you have a directory called `~/scripts` where you store your custom scripts. To add this directory to the PATH variable, you would add the following line to your .bashrc file:

```plaintext
export PATH="$PATH:/home/your_username/scripts"
```

Replace `your_username` with your actual username on the system. After saving and sourcing the .bashrc file, you'll be able to run any executable script in the `~/scripts` directory from any location on your system by simply typing the script name in the terminal.

%[https://linux101.hashnode.dev/setting-environment-variables-in-mac-easy-steps] 

## Conclusion

Adding new paths to the PATH variable by modifying your .bashrc file is a simple yet powerful technique that can greatly improve your productivity and efficiency when working with Linux.

By ensuring that the shell can locate your executable files and scripts from anywhere on the system, you'll save time and effort, and you'll be able to seamlessly run your programs and scripts without having to navigate to their specific directories.

With this knowledge, you'll be one step closer to becoming a proficient Linux user.
