The PATH Variable Explained for Beginners

CodingFlashlight
Nerd For Tech
Published in
3 min readApr 24, 2021

What is a PATH variable, and why do I need it? I will explain for beginners so that you will understand the concept better and know exactly when and why you need to set the PATH variable.

Photo by Jens Johnsson from Pexels

Paths Everywhere (Pun Intended)

Quite often, when you want to learn a (new) programming language, the introduction and installation tutorials ask you to add a PATH variable (e.g., C:/Programs/Java/JDK-12.0.1) to the environment variables. You do it, but do you know WHY you need to set the PATH variable? The explanations on the web are sometimes quite technical and they don’t help you understand the concept behind it.

The PATH Variable Explained

Computers are stupid. Really! Computers make very fast, very accurate mistakes. They do not know your intention of installing a new programming language — you have to tell them. With a PATH variable you do precisely that.

On Windows, Linux, and Mac OS X you use the PATH Variable. By setting the PATH variable in the environmental variables, you specify the directory of the executable program — in our case, the directory of our programming language. With the PATH variable, you tell the Operating System where to look in order to start a program, and the environmental variable is the place where the Operating System expects this kind of information.

Why Do I Need the PATH Variable?

You don’t — but it makes life easier. Before setting the PATH variable you must write the whole path to your programming languages executable in a Terminal. Let’s suppose we want to compile a Java program. To do that, we have to type the following

C:/Programs/Java/JDK-12.0.1/bin/javac HelloWorld.java

in order to compile a written program in Java. That’s annoying and time-consuming. With a PATH variable, the Operating System knows where to look for whenever you want to execute a program. Now you just have to write

javac HelloWorld.java

and the Operating System knows where to find the executable program (in our case ‘javac’) on your machine. Great, isn’t it? On a high-level basis that is everything there is to know.

Take a look at your environmental variables on your machine. You will probably see that some installed programs already set some of those variables by themselves, and some are already set by the Operating System.

Try It Out!

The best way to understand something better is by trying it out with an easy example. Open a terminal of your choice and try to open a program — let’s say Chrome. It won’t work, but it will if you enter the whole path. Now add the path of your Chrome installation to your environmental variables and try it out once again without the entire path. Now it should work.

Now you should have a good understanding of the PATH variable and be even able to explain it to other programming beginners.

Thanks for reading.

Originally published at https://codingflashlight.com on April 24, 2021.

--

--

CodingFlashlight
Nerd For Tech

Sharing insights on how to start coding and become a developer: www.codingflashlight.com | Twitter: @coding_flshlght