How to set the PATH variable in Linux (2 ways)

How to set the PATH variable in Linux (2 ways)

HomeGames, Guides, How toHow to set the PATH variable in Linux (2 ways)

The PATH variable in Linux is an important component that contains the list of directories that contain the commands that can be entered using the command line interface. It is similar to environment variables on Windows. Most modern apps with a GUI interface do not require you to specify a PATH variable. You can change the PATH variable to tell the Linux machine in which directories to look for commands to run. In this guide, let's look at how to set the PATH variable in Linux.

How to set environment variables in Linux

One of the easiest ways to set a default PATH variable permanently on Linux is by editing the .bashrc file. For the unaware, it is a script file that runs when a user logs into their session and it helps connect user commands by directing them to the default directories stored in it. Here's how to add a new PATH variable to .bashrc.

1. Start the terminal and open the .bashrc file with your favorite Linux text editor. We will use the nano editor and don't forget sudo.

2. Go to the end of the file and start typing the default path you want to add after adding export=$PATH:. We choose the path to the download folder as an example, but you must choose the path that leads to your program. The end result should look like this.

Tagged:
How to set the PATH variable in Linux (2 ways).
Want to go more in-depth? Ask a question to learn more about the event.