{"id":26408,"date":"2021-01-04T17:17:13","date_gmt":"2021-01-04T08:17:13","guid":{"rendered":"https:\/\/tadtadya.com\/en\/?p=26408"},"modified":"2021-01-04T17:17:21","modified_gmt":"2021-01-04T08:17:21","slug":"how-to-set-environment-variable-path","status":"publish","type":"post","link":"https:\/\/tadtadya.com\/en\/how-to-set-environment-variable-path\/","title":{"rendered":"PATH settings (environment variables for Windows, Mac, Linux, and Unix)"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p>I will explain how to set them for Windows, Mac, Linux, and Unix.<\/p>\n\n\n\n<p>It's easy to do. Please feel free to take a look.<\/p>\n\n\n\n<!--more-->\n\n\n\n<div class=\"wp-block-origin-block-msg-box\"><div class=\"msgbox msgbox-notice v1\"><i class=\"fas fa-exclamation-triangle icon\"><\/i><div class=\"msg\">\n<p>This is written by a Japanese who can't speak English with the help of translation application. Sorry if it's not good.<\/p>\n<\/div><\/div><\/div>\n\n\n<div id=\"toc\" class=\"idx-lst\">\n\t<input type=\"checkbox\" class=\"chk\" id=\"idx-lst-chk\" name=\"btn\" \/>\n\t<label class=\"idx-lst-hd\" for=\"idx-lst-chk\"><i class=\"fa-solid fa-check-double\"><\/i>Contents<\/label>\n\t<div class=\"idx-lst-bd\">\n\t\t<ul class=\"idx-lst-ul\">\n\t\t\t\t\t\t\t\t<li class=\"idx-lst-li idt0\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa-regular fa-hand-point-right ico\"><\/i>\n\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"#environment-variable-path\" title=\"What is the PATH environment variable?\">What is the PATH environment variable?<\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t\t\t\t\t\t\t<li class=\"idx-lst-li idt0\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa-regular fa-hand-point-right ico\"><\/i>\n\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"#mac-linux\" title=\"PATH settings for Mac and Linux\">PATH settings for Mac and Linux<\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t\t\t\t\t\t\t<li class=\"idx-lst-li idt1\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa-regular fa-hand-point-right ico\"><\/i>\n\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"#mac-redhat\" title=\"PATH settings for Mac and Redhat-based Linux\">PATH settings for Mac and Redhat-based Linux<\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t\t\t\t\t\t\t<li class=\"idx-lst-li idt1\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa-regular fa-hand-point-right ico\"><\/i>\n\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"#debian-unix\" title=\"PATH settings for Debian-based Linux and Unix\">PATH settings for Debian-based Linux and Unix<\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t\t\t\t\t\t\t<li class=\"idx-lst-li idt0\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa-regular fa-hand-point-right ico\"><\/i>\n\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"#windows\" title=\"PATH settings for Windows\">PATH settings for Windows<\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t\t\t\t\t\t\t<li class=\"idx-lst-li idt0\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa-regular fa-hand-point-right ico\"><\/i>\n\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"#conclusion\" title=\"Summary\">Summary<\/a>\n\t\t\t\t\t<\/li>\n\t\t\t\t\t\t\t<\/ul>\n\t<\/div>\n<\/div>\n\n\n\n\n<h2 class=\"is-style-h2df\" id=\"environment-variable-path\">What is the PATH environment variable?<\/h2>\n\n\n\n<p>First, what is an environment variable?<\/p>\n\n\n\n<div class=\"wp-block-origin-block-a-link-ext alk-ex center\"><a href=\"#mac-linux\" title=\"If you know, skip it.\"><strong>If you know, skip it.<\/strong> <i class=\"fas fa-angle-double-right\"><\/i><\/a><\/div>\n\n\n\n<p>Environment variables are constants used by the operating system and applications installed in the operating system. They are usually written in capital letters.<\/p>\n\n\n\n<p>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 <strong><span class=\"marker-blue\">variable<\/span><\/strong> in the OS <strong><span class=\"marker-blue\">environment<\/span><\/strong>.<\/p>\n\n\n\n<p>The OS or application will retrieve the value from the environment variable and refer to it when needed.<\/p>\n\n\n\n<h3 class=\"is-style-h3df\">PATH is a special kind of environment variable.<\/h3>\n\n\n\n<p>Among the environment variables, PATH is a little different: PATH defines the commands of the program you want to run from any location.<\/p>\n\n\n\n<p>(A command that can be run from any directory.)<\/p>\n\n\n\n<p>For example, the command \"php\", which executes PHP, will result in an error if it is not added to the PATH environment variable.<\/p>\n\n\n\n<p>In order to run the php command, you have to do the following<\/p>\n\n\n\n<div class=\"pre-code-title\"><\/div><pre class=\" command-line\" data-user=\"\" data-output=\"\"><code class=\"language-bash\">\/usr\/bin\/php<\/code><\/pre>\n\n\n\n<p>'\/usr\/bin\/php' is the full path where the php command is installed.<\/p>\n\n\n\n<div class=\"wp-block-origin-block-em-box em-group em-group-note\">\n<p>'\/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.<\/p>\n\n\n\n<p>In fact, php commands in '\/usr\/bin' can be executed as \"php\" without changing the PATH.<\/p>\n<\/div>\n\n\n\n<h3 class=\"is-style-h3df\">PATH is a shortcut for the command<\/h3>\n\n\n\n<p>This is a hassle. Each time you run a command, you have to type a long command.<\/p>\n\n\n\n<p>The solution to this hassle is PATH, which allows you to enter commands as usual by adding \"\/usr\/bin\/\" to the PATH value.<\/p>\n\n\n\n<div class=\"pre-code-title\"><\/div><pre class=\" command-line\" data-user=\"\" data-output=\"\"><code class=\"language-bash\">php<\/code><\/pre>\n\n\n\n<p>It allows commands to be executed from any location. This is the reason why we set the PATH regardless of the programming language.<\/p>\n\n\n\n<div class=\"wp-block-origin-block-em-box em-group em-group-default\">\n<ul><li>java<\/li><li>php<\/li><li>python<\/li><\/ul>\n<\/div>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>The PATH is there to make it easy to run commands from that freely placed source location.<\/p>\n\n\n\n<div class=\"wp-block-origin-block-em-box em-group em-group-note\">\n<p>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.<\/p>\n\n\n\n<p>System environment variables can be used by all users.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-origin-block-em-box em-group em-group-note\">\n<p>In Windows, when referring to an environment variable,<\/p>\n\n\n\n<div class=\"wp-block-origin-block-em-box em-group em-group-default\">\n<p>%PATH%<\/p>\n<\/div>\n\n\n\n<p>On Mac, Linux, and Unix,<\/p>\n\n\n\n<div class=\"wp-block-origin-block-em-box em-group em-group-default\">\n<p>$PATH<\/p>\n<\/div>\n\n\n\n<p>These are the rules.<\/p>\n<\/div>\n\n\n\n<h2 class=\"is-style-h2df\" id=\"mac-linux\">PATH settings for Mac and Linux<\/h2>\n\n\n\n<p>There are two ways to set the PATH: Windows and other.<\/p>\n\n\n\n<p>macOS was developed based on Unix, and Linux was also inspired by Unix, so they are very similar.<\/p>\n\n\n\n<p>So Mac and Linux will work the same.<\/p>\n\n\n\n<div class=\"wp-block-origin-block-em-box em-group em-group-note\">\n<p>The name \"Linux\" comes from \"like a Unix\", which started as an imitation of Unix and spread to surpass the original Unix before long.<\/p>\n<\/div>\n\n\n\n<h3 class=\"is-style-h3df\" id=\"mac-redhat\">PATH settings for Mac and Redhat-based Linux<\/h3>\n\n\n\n<p>Mac and Redhat Linux (CentOS, Fedora, etc.) are internally made up of a collection of commands called bash.<\/p>\n\n\n\n<p>The way to set the PATH follows the rules of bash. There is one file to edit, .bash_profile.<\/p>\n\n\n\n<div class=\"wp-block-origin-block-em-box em-group em-group-note\">\n<p>.bash_profile is a hidden file in the home directory of the root user and each user.<\/p>\n\n\n\n<p>Hidden files cannot be seen without the -a option of the ls command.<\/p>\n\n\n\n<div class=\"pre-code-title\"><\/div><pre class=\" command-line\" data-user=\"\" data-output=\"\"><code class=\"language-bash\">ls -altr<\/code><\/pre>\n<\/div>\n\n\n\n<div class=\"wp-block-origin-block-em-box em-group em-group-note\">\n<p>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.<\/p>\n\n\n\n<p>The root user's file is rarely used for security reasons. Let's add it to the user environment variable.<\/p>\n<\/div>\n\n\n\n<div class=\"pre-code-title\">.bash_profile before editing<\/div><pre class=\"\"><code class=\"language-vim\">PATH=$PATH:$HOME\/.local\/bin:$HOME\/bin\nexport PATH<\/code><\/pre>\n\n\n\n<p>The .bash_profile already has this defined.<\/p>\n\n\n\n<div class=\"wp-block-origin-block-em-box em-group em-group-default\">\n<p>PATH=$PATH:<\/p>\n<\/div>\n\n\n\n<p>The colon (:) is a delimiter, meaning \"add to the already defined PATH\".<\/p>\n\n\n\n<p>When you add a new one, keep the one that was originally there and add it.<\/p>\n\n\n\n<p>Be careful not to delete the original description. This will cause the application to have some sort of problem.<\/p>\n\n\n\n<div class=\"pre-code-title\">.bash_profile after editing<\/div><pre class=\"\"><code class=\"language-vim\">PATH=$PATH:$HOME\/.local\/bin:$HOME\/bin:$HOME\/shell<\/code><\/pre>\n\n\n\n<div class=\"wp-block-origin-block-em-box em-group em-group-point\">\n<p>\"PATH=$PATH:\" copies the system environment variables to the user environment variables.<\/p>\n\n\n\n<p>The one written after it is the original user environment variable.<\/p>\n<\/div>\n\n\n\n<p>This is all you need to edit the file. The last step is to reflect the edited contents to the OS.<\/p>\n\n\n\n<div class=\"pre-code-title\">Update .bash_profile<\/div><pre class=\" command-line\" data-user=\"\" data-output=\"\"><code class=\"language-bash\">source ~\/.bash_profile<\/code><\/pre>\n\n\n\n<div class=\"wp-block-origin-block-em-box em-group em-group-note\">\n<p>You don't need to run the source command, just log back in from the terminal and it will be reflected.<\/p>\n\n\n\n<p>However, if you run the source command, you don't need to re-login to the terminal.<\/p>\n<\/div>\n\n\n\n<h3 class=\"is-style-h3df\" id=\"debian-unix\">PATH settings for Debian-based Linux and Unix<\/h3>\n\n\n\n<p>Debian-based Linux (such as Ubuntu) and Unix do not have bash as their default shell.<\/p>\n\n\n\n<p>So, the file to edit is not .bash_profile. It will be .profile.<\/p>\n\n\n\n<p>The only other difference is that the PATH definition is enclosed in double quotation marks (\").<\/p>\n\n\n\n<div class=\"pre-code-title\">PATH definition in .profile<\/div><pre class=\"\"><code class=\"language-vim\">PATH=\"$PATH:$HOME\/.local\/bin:$HOME\/bin\"<\/code><\/pre>\n\n\n\n<div class=\"wp-block-origin-block-em-box em-group em-group-note\">\n<p>Some of them are not enclosed in double quotation marks as in bash. These rules should match the original definition.<\/p>\n<\/div>\n\n\n\n<p>Then, update the .profile with the source command and you are done.<\/p>\n\n\n\n<div class=\"pre-code-title\">Update the .profile<\/div><pre class=\" command-line\" data-user=\"\" data-output=\"\"><code class=\"language-bash\">source ~\/.profile<\/code><\/pre>\n\n\n\n<h2 class=\"is-style-h2df\" id=\"windows\">PATH settings for Windows<\/h2>\n\n\n\n<p>Windows has evolved in a unique way compared to other operating systems, so they do not work the same.<\/p>\n\n\n\n<p>It is faster to work on the desktop in Windows. Or rather, no one works with commands.<\/p>\n\n\n\n<h3 class=\"is-style-h3df\">Open the environment variable editing window.<\/h3>\n\n\n\n<p>First, open the environment variable editing window.<\/p>\n\n\n\n<p>Right-click on the PC (formerly My Computer) icon and select Properties.<\/p>\n\n\n\n<p>You should see a 'System' window. This can also be viewed in the 'System' section of the 'Control Panel'.<\/p>\n\n\n\n<p>You can also start the System in the Control Panel by typing \"System\" in the search box at the bottom left of the desktop.<\/p>\n\n\n\n<p>Next, select \"Advanced System Settings\" from the left menu.<\/p>\n\n\n\n<p>Press the 'Environment Variables' button in the 'Advanced' tab.<\/p>\n\n\n\n<h3 class=\"is-style-h3df\">Edit environment variables<\/h3>\n\n\n\n<p>When the Environment Variables window appears, double-click on the Path user environment variable, or select Path and click the Edit button.<\/p>\n\n\n\n<p>Then, press the New button and enter a path to add a new path.<\/p>\n\n\n\n<p>Finally, click the OK button to exit.<\/p>\n\n\n\n<p>That's all there is to it in Windows.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<div class=\"wp-block-origin-block-em-box em-group em-group-note\">\n<p>If you look closely, you can see that only Windows is a little different.<\/p>\n\n\n\n<ul><li>Variable name is 'Path' instead of 'PATH<\/li><li>The separator is not a colon (:), but a semicolon (;).<\/li><\/ul>\n<\/div>\n\n\n\n<h2 class=\"is-style-h2df\" id=\"conclusion\">Summary<\/h2>\n\n\n\n<p>Setting the PATH is easy.<\/p>\n\n\n\n<div class=\"wp-block-origin-block-em-box em-group em-group-default\">\n<p>Windows and the rest<\/p>\n<\/div>\n\n\n\n<p>If you remember these two methods, you can work with almost any OS.<\/p>\n\n\n\n<p>Even so, I sometimes forget to do so, and I say\u2026<\/p>\n\n\n\n<p>The person who needs this content the most is me.<\/p>\n\n<!-- WP QUADS Content Ad Plugin v. 2.0.65.1 -->\n<div class=\"quads-location quads-ad2\" id=\"quads-ad2\" style=\"float:none;margin:0px;\">\n<ul class=\"quads-location-ul\">\r\n<li class=\"quads-location-li li-1\">\r\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block\"\r\n     data-ad-client=\"ca-pub-4926008942376207\"\r\n     data-ad-slot=\"6550760310\"\r\n     data-ad-format=\"auto\"\r\n     data-full-width-responsive=\"true\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\r\n<\/li>\r\n<li class=\"quads-location-li li-2\">\r\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block\"\r\n     data-ad-client=\"ca-pub-4926008942376207\"\r\n     data-ad-slot=\"6550760310\"\r\n     data-ad-format=\"auto\"\r\n     data-full-width-responsive=\"true\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\r\n<\/li>\r\n<\/ul>\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>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.<\/p>\n","protected":false},"author":1,"featured_media":12973,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"There are two main ways to set the PATH for an operating system.\n\nThis can be done for most operating systems.\n\n#PATH\n#OperatingSystem\n#Unix\n#Linux\n#Windows\n#Ubuntu\n#CentOS\n#Fedora\n","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_options":[]},"categories":[9],"tags":[87,224,311,557,558,559,560,561],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/tadtadya.com\/en\/wp-content\/uploads\/sites\/2\/2018\/11\/1623193_s_wi.jpg?fit=640%2C480&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8Qw77-6RW","jetpack_likes_enabled":false,"_links":{"self":[{"href":"https:\/\/tadtadya.com\/en\/wp-json\/wp\/v2\/posts\/26408"}],"collection":[{"href":"https:\/\/tadtadya.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tadtadya.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tadtadya.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tadtadya.com\/en\/wp-json\/wp\/v2\/comments?post=26408"}],"version-history":[{"count":0,"href":"https:\/\/tadtadya.com\/en\/wp-json\/wp\/v2\/posts\/26408\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tadtadya.com\/en\/wp-json\/wp\/v2\/media\/12973"}],"wp:attachment":[{"href":"https:\/\/tadtadya.com\/en\/wp-json\/wp\/v2\/media?parent=26408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tadtadya.com\/en\/wp-json\/wp\/v2\/categories?post=26408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tadtadya.com\/en\/wp-json\/wp\/v2\/tags?post=26408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}