{"id":365763,"date":"2021-11-11T21:00:00","date_gmt":"2021-11-11T18:00:00","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/what-is-the-unix-path-and-how-do-you-add-programs-to-it-cloudsavvy-it\/"},"modified":"2021-11-11T21:00:00","modified_gmt":"2021-11-11T18:00:00","slug":"what-is-the-unix-path-and-how-do-you-add-programs-to-it-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/what-is-the-unix-path-and-how-do-you-add-programs-to-it-cloudsavvy-it\/","title":{"rendered":"#What Is the Unix PATH, and How Do You Add Programs To it? \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2edcb03261f\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2edcb03261f\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/what-is-the-unix-path-and-how-do-you-add-programs-to-it-cloudsavvy-it\/#What_Does_The_PATH_Do\" >What Does The PATH Do?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/what-is-the-unix-path-and-how-do-you-add-programs-to-it-cloudsavvy-it\/#How_To_Add_Folders_To_The_PATH\" >How To Add Folders To The PATH<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/what-is-the-unix-path-and-how-do-you-add-programs-to-it-cloudsavvy-it\/#Consider_Using_Symlinks\" >Consider Using Symlinks<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/what-is-the-unix-path-and-how-do-you-add-programs-to-it-cloudsavvy-it\/#The_PATH_Can_Change\" >The PATH Can Change<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#What Is the Unix PATH, and How Do You Add Programs To it? \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage alignnone size-full wp-image-1938\" srcset=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/09\/d0f34641.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/09\/d0f34641.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/09\/d0f34641.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"700\" height=\"300\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>The Unix PATH is an environment variable that tells the shell which directories it should look for when you issue commands. You can think of it like a list of <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">App<\/a>lication or Program Files folders.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"What_Does_The_PATH_Do\"><\/span>What Does The PATH Do?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you wanted to run a binary in your current folder, you\u2019d have to provide a relative path, like so:<\/p>\n<pre>.\/command [args]<\/pre>\n<p>But, if you move that binary to a folder like <code>\/usr\/local\/bin\/<\/code>, you instead simply type the command name to run it:<\/p>\n<pre>command [args]<\/pre>\n<p>This is because <code>\/usr\/local\/bin\/<\/code>\u00a0is on the PATH. The shell knows to look in that folder if you don\u2019t specify a location. Many command line utilities are installed here, and in similar folders. You can view which folders are on your PATH by echoing the variable itself, using the <code>$<\/code>\u00a0prefix:<\/p>\n<pre>echo $PATH<\/pre>\n<p>By default though, the PATH variable is a list of directory names split by colons. It\u2019s not very readable:<\/p>\n<pre>\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin:\/usr\/<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/game\/\" data-internallinksmanager029f6b8e52c=\"7\" title=\"Game\" target=\"_blank\" rel=\"noopener\">game<\/a>s:\/usr\/local\/games:\/snap\/bin<\/pre>\n<p>But, with a bit of\u00a0regex, you can clean it up to print out a list:<\/p>\n<pre>echo $PATH | sed $'s\/:\/\\n\/g'<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1934\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/09\/b72ff2b8.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"700\" height=\"300\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>These directories all serve different purposes:<\/p>\n<ul>\n<li>Folders ending in <code>bin<\/code>\u00a0are <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/general\/\" data-internallinksmanager029f6b8e52c=\"3\" title=\"General\" target=\"_blank\" rel=\"noopener\">general<\/a> purpose, folders ending in <code>sbin<\/code>\u00a0are intended for system administration commands, things the system runs but you probably won\u2019t interact with much. Though there are<\/li>\n<li><code>\/bin<\/code>\u00a0and <code>\/sbin<\/code>\u00a0are intended for programs that the system needs before <code>\/usr<\/code>\u00a0is available. This is where key programs like <code>sh<\/code>\u00a0and <code>ls<\/code>\u00a0are stored.<\/li>\n<li><code>\/usr\/bin<\/code>\u00a0and <code>\/usr\/sbin<\/code>\u00a0are for normal user programs, usually built in to the OS.<\/li>\n<li><code>\/usr\/local\/bin<\/code>\u00a0and <code>\/usr\/local\/sbin<\/code>\u00a0are for programs you\u2019ve downloaded or compiled yourself. If you have a binary you downloaded, and don\u2019t know where to put it, chuck it in <code>\/usr\/local\/bin<\/code>.<\/li>\n<\/ul>\n<p><code>\/usr\/local\/sbin<\/code>\u00a0may not even exist on your system, as it\u2019s fairly contradictory in nature. It isn\u2019t present on macOS, but contains a few programs on Ubuntu.<\/p>\n<p>You can view which folders different commands are located in with the\u00a0<code>which<\/code>\u00a0command:<\/p>\n<pre>which ls<\/pre>\n<p>Which will print out the full path leading to the given command.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"How_To_Add_Folders_To_The_PATH\"><\/span>How To Add Folders To The PATH<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Adding a folder to the PATH is simple, you just have to set the variable. But you can\u2019t overwrite it completely, so you instead add a folder to the front of the PATH:<\/p>\n<pre>PATH=~\/folder:$PATH<\/pre>\n<p>You can also tack the folder onto the back of the PATH:<\/p>\n<pre>PATH=$PATH:~\/folder<\/pre>\n<p>These have different uses. Folders close to the front will be checked first, so if there are duplicate commands (for example, two versions of Python, both called \u201c<code>python<\/code>\u201c) adding the folder to the front will ensure the folder you added manually will be checked first. Most of the time, this is probably what you want.<\/p>\n<p>Usually, you\u2019ll define this in your shell\u2019s profile, which will set the variable whenever you open a new terminal. If you\u2019re using bash, this is either <code>.bash_profile<\/code>\u00a0or <code>.bashrc<\/code>. If you\u2019re using a shell like zsh, this will be a different file (<code>.zshrc<\/code>\u00a0in this case). If there\u2019s already a definition, you can simply add your folder to the front of the list, separated by a colon.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Consider_Using_Symlinks\"><\/span>Consider Using Symlinks<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Rather than adding a folder directly, you can instead use a symlink to specific commands, and place the symlink in<code>\/usr\/local\/bin<\/code>. For example, Python installs to its own folder, but rather than adding that folder to the PATH, it uses a symlink. You can view where symlinks lead with <code>ls -la<\/code>:<\/p>\n<pre>ls -la $(which python)<\/pre>\n<p>And you can create symlinks with <code>ln<\/code>:<\/p>\n<pre>ln -s command \/usr\/local\/bin\/command<\/pre>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"The_PATH_Can_Change\"><\/span>The PATH Can Change<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Since the PATH variable is usually defined in <code>.bashrc<\/code>, your PATH may be different when running in a different environment. This is particularly relevant if you\u2019re running inside a bash script, or if you\u2019re running a command via <code>cron<\/code>. If you\u2019re having \u201ccommand not found\u201d issues, you\u2019ll want to double check that the PATH is set correctly in the environment you\u2019re running in.\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/1933\/what-is-the-unix-path-and-how-do-you-add-programs-to-it\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#What Is the Unix PATH, and How Do You Add Programs To it? \u2013 CloudSavvy IT&#8221; The Unix PATH is an environment variable that tells the shell which directories it should look for when you issue commands. You can think of it like a list of Application or Program Files folders. What Does The PATH&#8230;<\/p>\n","protected":false},"author":1,"featured_media":365764,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/09\/d0f34641.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-365763","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/365763","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=365763"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/365763\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/365764"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=365763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=365763"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=365763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}