Path

What is it?

When you run ls or any command, how does Linux know where to find the right binary? Well, that’s where path comes in. It’s a special environment variable that contains paths to directories, separated by colons. When you enter a command, Linux will search through the path for a matching binary in each directory and execute the first one it finds. Its value is set on the system by default. But it’s common to customize it by using the export keyword which will set the value for an environment variable. The most common technique is to update the path for an individual user by customizing the .bashrc file, which itself is a script that will run before every terminal session.

Adding to path

  1. Run sudo vim /etc/environment
  2. Now, append the variable for the software that you want to add to your path
    PATH="...bin:/mnt/c/Program Files/Java/jdk-<YOUR-VERSION>/bin"
    
  3. Save and exit the buffer
  4. Do not forget to add : between bin and /mnt
  5. source /etc/environment

Where is the PATH

Linux

To check the PATH, logged in as yourself, run the command (from the system terminal), type

env | grep PATH

Windows

Open git bash and run this

$ echo ~
/c/Users/<username>

" is usually your ~C:\Users\<your user name> folder. Typing echo ~ in the Git Bash terminal will tell you what that folder is.

Path issues

If you see an error like this:

The command could not be located because 'usr/bin' is not included in the PATH environment variable

edit .bashrc in your home directory (.zshrc in Macbook) and add the the following line:

export PATH="/path/to/dir:$PATH"

You will need to source your .bashrc or logout/login (or restart the terminal) for the changes to take effect.

To source your .bashrc, simply type

$ source ~/.bashrc