Send by LINE
B! Bookmarks in Hate-bu
Bookmarks in Pocket
RSS feeds

PATH settings (environment variables for Windows, Mac, Linux, and Unix)

programing image

One of the basic tasks in building a program development environment is to set environment variables. No matter which programming language you use, you will always experience this.

I will explain how to set them for Windows, Mac, Linux, and Unix.

It's easy to do. Please feel free to take a look.

This is written by a Japanese who can't speak English with the help of translation application. Sorry if it's not good.

What is the PATH environment variable?

First, what is an environment variable?

Environment variables are constants used by the operating system and applications installed in the operating system. They are usually written in capital letters.

Since it is used many times and in many different places, and defining the values one by one is tedious, we will define it as a variable in the OS environment.

The OS or application will retrieve the value from the environment variable and refer to it when needed.

PATH is a special kind of environment variable.

Among the environment variables, PATH is a little different: PATH defines the commands of the program you want to run from any location.

(A command that can be run from any directory.)

For example, the command "php", which executes PHP, will result in an error if it is not added to the PATH environment variable.

In order to run the php command, you have to do the following


'/usr/bin/php' is the full path where the php command is installed.

'/usr/bin' is the default installation directory for application execution commands in Unix and Linux-based operating systems, and is added to the PATH system environment variable.

In fact, php commands in '/usr/bin' can be executed as "php" without changing the PATH.

PATH is a shortcut for the command

This is a hassle. Each time you run a command, you have to type a long command.

The solution to this hassle is PATH, which allows you to enter commands as usual by adding "/usr/bin/" to the PATH value.


It allows commands to be executed from any location. This is the reason why we set the PATH regardless of the programming language.

  • java
  • php
  • python

These are the commands that are always executed in program development. And the program source files are freely placed and worked on anywhere by the user.

The PATH is there to make it easy to run commands from that freely placed source location.

There are two types of environment variables: system environment variables that are used by the entire OS, and user environment variables that can only be used by specific users.

System environment variables can be used by all users.

In Windows, when referring to an environment variable,


On Mac, Linux, and Unix,


These are the rules.

PATH settings for Mac and Linux

There are two ways to set the PATH: Windows and other.

macOS was developed based on Unix, and Linux was also inspired by Unix, so they are very similar.

So Mac and Linux will work the same.

The name "Linux" comes from "like a Unix", which started as an imitation of Unix and spread to surpass the original Unix before long.

PATH settings for Mac and Redhat-based Linux

Mac and Redhat Linux (CentOS, Fedora, etc.) are internally made up of a collection of commands called bash.

The way to set the PATH follows the rules of bash. There is one file to edit, .bash_profile.

.bash_profile is a hidden file in the home directory of the root user and each user.

Hidden files cannot be seen without the -a option of the ls command.

ls -altr

The .bash_profile file for the root user is the system environment variable, and the files for other users are the user environment variable settings.

The root user's file is rarely used for security reasons. Let's add it to the user environment variable.

.bash_profile before editing
export PATH

The .bash_profile already has this defined.


The colon (:) is a delimiter, meaning "add to the already defined PATH".

When you add a new one, keep the one that was originally there and add it.

Be careful not to delete the original description. This will cause the application to have some sort of problem.

.bash_profile after editing

"PATH=$PATH:" copies the system environment variables to the user environment variables.

The one written after it is the original user environment variable.

This is all you need to edit the file. The last step is to reflect the edited contents to the OS.

Update .bash_profile
source ~/.bash_profile

You don't need to run the source command, just log back in from the terminal and it will be reflected.

However, if you run the source command, you don't need to re-login to the terminal.

PATH settings for Debian-based Linux and Unix

Debian-based Linux (such as Ubuntu) and Unix do not have bash as their default shell.

So, the file to edit is not .bash_profile. It will be .profile.

The only other difference is that the PATH definition is enclosed in double quotation marks (").

PATH definition in .profile

Some of them are not enclosed in double quotation marks as in bash. These rules should match the original definition.

Then, update the .profile with the source command and you are done.

Update the .profile
source ~/.profile

PATH settings for Windows

Windows has evolved in a unique way compared to other operating systems, so they do not work the same.

It is faster to work on the desktop in Windows. Or rather, no one works with commands.

Open the environment variable editing window.

First, open the environment variable editing window.

Right-click on the PC (formerly My Computer) icon and select Properties.

You should see a 'System' window. This can also be viewed in the 'System' section of the 'Control Panel'.

You can also start the System in the Control Panel by typing "System" in the search box at the bottom left of the desktop.

Next, select "Advanced System Settings" from the left menu.

Press the 'Environment Variables' button in the 'Advanced' tab.

Edit environment variables

When the Environment Variables window appears, double-click on the Path user environment variable, or select Path and click the Edit button.

Then, press the New button and enter a path to add a new path.

Finally, click the OK button to exit.

That's all there is to it in Windows.

In the past it was necessary to restart the PC, but now it is not necessary. If you reopen the command prompt, the PATH will be reflected.

If you look closely, you can see that only Windows is a little different.

  • Variable name is 'Path' instead of 'PATH
  • The separator is not a colon (:), but a semicolon (;).


Setting the PATH is easy.

Windows and the rest

If you remember these two methods, you can work with almost any OS.

Even so, I sometimes forget to do so, and I say…

The person who needs this content the most is me.

Leave a Reply