Adding a PATH variable in Windows

Before we begin, Let's understand What PATH variables are and Why it is used!

What are PATH variables and Why do we use them?

For developers, The command line interface ( CLI ) has to be a weapon that we most often use. When you run commands in the CLI, it knows what you want to execute and does it for you. But if you try to run commands that are internally or natively not a part of Windows, the Operating System will throw an error, make not recognized as an internal or external command. In such cases, you’ll need to add it to your PATH variable before your system can recognize such a command. PATH is an environment variable. Environment variables store data about a system’s environment and they tell your machine where to look for programs ( .exe or executables ) when you ask for them. The PATH variable is one of the most well-known environment variables since it exists on Windows, Mac, and Linux machines. Its actual form is just a text string containing a list of directory paths that the system will search every time you request a program by running a command including the name of the executable file.

Adding a PATH variable in a Windows Machine:

Step 1: Open the System Properties window.

  • Right-click on the "This PC" or "My Computer" icon on your desktop or in File Explorer.

  • Select "Properties" from the context menu.

Step 2: Access the Advanced system settings.

  • In the System window, click on "Advanced system settings" in the left-hand pane. This will open the System Properties window.

Step 3: Open the Environment Variables window.

  • In the System Properties window, click on the "Environment Variables..." button at the bottom.

Step 4: Add a new user or system environment variable.

  • In the Environment Variables window, you'll see two sections: User variables for <username> and System variables.

  • If you want the variable to be available only for your user account, click on the "New..." button under "User variables." If you want the variable to be available system-wide for all users, click on the "New..." button under "System variables."

Step 5: Enter the variable name and value.

  • In the "New User Variable" or "New System Variable" dialogue box:

    • For "Variable name," enter the name of the environment variable (e.g., MY_VAR_NAME).

    • For "Variable value," enter the value you want to assign to the variable (e.g., C:\my\path\to\folder).

Step 6: Save the changes and close the windows.

  • Click "OK" to save the new environment variable.

  • Close the Environment Variables window.

  • Close the System Properties window.

Step 7: (Optional) Restart your computer.

  • In some cases, you might need to restart your computer for the changes to take effect.

That's it! You have successfully added a new environment variable in Windows. The variable will now be available for use in your applications and scripts. Remember that if you added a user environment variable, it will only be accessible for your user account, whereas a system environment variable will be available for all users on the computer.