{"id":47473,"date":"2024-11-04T11:13:51","date_gmt":"2024-11-04T11:13:51","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=47473"},"modified":"2024-11-04T11:13:51","modified_gmt":"2024-11-04T11:13:51","slug":"add-path-variables-ubuntu","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2024\/11\/add-path-variables-ubuntu\/","title":{"rendered":"How to Add PATH Variables in Ubuntu 24.04"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/terminal-logo.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-37909\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/terminal-logo-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/terminal-logo-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/terminal-logo-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/terminal-logo-600x600.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/terminal-logo-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/terminal-logo.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>This tutorial shows how to configure PATH environment variables. Though title said for Ubuntu 24.04, it works in most Linux systems.<\/p>\n<p>PATH specifies the directories in which the executable files of programs are located on the system. Without knowing or typing the full path to the file, just type the app name in the command line, then your system will look into the path directories and run the first that matches.<\/p>\n<p>For example, type <code>firefox<\/code> in command line will run <code>\/usr\/bin\/firefox<\/code> to launch Firefox web browser in Ubuntu, Fedora, and other Linux that use the browser as default.<\/p>\n<p><!--more--><\/p>\n<p>Common Linux packages (e.g., <code>.deb<\/code>, <code>.rpm<\/code>) will mostly install their executable files into the PATH automatically. For portable Linux package and others, user can manually add the app folders, that contain the executable files, into PATH.<\/p>\n<h3>Check current PATH Variables<\/h3>\n<p>Most Linux by default includes <code>\/usr\/bin<\/code>, <code>\/usr\/local\/bin<\/code>, <code>\/usr\/sbin<\/code>, <code>\/usr\/local\/sbin<\/code>, <code>\/usr\/games<\/code>, <code>\/usr\/local\/games<\/code> directories into PATH. While, third-party apps may add more.<\/p>\n<p>To tell the current PATH variables, open terminal (Ctrl+Alt+T) and run command:<\/p>\n<pre>echo $PATH<\/pre>\n<p>It will print all the PATH directories separated with colon (:).<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/check-path.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47474\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/check-path-700x247.webp\" alt=\"\" width=\"610\" height=\"215\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/check-path-700x247.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/check-path-300x106.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/check-path.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Option 1: Add a folder\/directory into PATH for temporary use.<\/h3>\n<p>For developing or other purpose, you may add a custom folder or directory into PATH that works only for current terminal window or command console.<\/p>\n<p><b>To add custom folder into PATH<\/b>, for current terminal only, use either command below:<\/p>\n<pre>export PATH=\"\/PATH\/TO\/CUSTOM\/FOLDER:$PATH\"<\/pre>\n<p>or:<\/p>\n<pre>export PATH=\"$PATH:\/PATH\/TO\/CUSTOM\/FOLDER\"<\/pre>\n<p>For example, I downloaded SweetHome3D tarball and extracted into &#8220;MyApps&#8221; sub-folder into user home. To add it into PATH, for current terminal only, use command:<\/p>\n<pre>export PATH=\"\/home\/ji\/MyApps\/SweetHome3D-7.5:$PATH\"<\/pre>\n<p>It added that folder into the beginning of PATH.<\/p>\n<p>For choice, the command below will add it to the end.<\/p>\n<pre>export PATH=\"$PATH:\/home\/ji\/MyApps\/SweetHome3D-7.5<\/pre>\n<p><b>NOTE: When running a command, it looks into path directories from beginning to end. The first one that matches will be run.<\/b><\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/add-path-terminal.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47475\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/add-path-terminal-700x430.webp\" alt=\"\" width=\"610\" height=\"375\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/add-path-terminal-700x430.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/add-path-terminal-300x184.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/add-path-terminal-768x471.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/add-path-terminal.webp 810w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Option 2: Add PATH Variables for Current Users Only<\/h3>\n<p>For current user only, just edit one of the below files for adding PATH variables:<\/p>\n<ul>\n<li><b>.bash_profile<\/b> &#8211; usually in use in Fedora, Manjaro Linux.<\/li>\n<li><b>.bash_login<\/b><\/li>\n<li><b>.profile<\/b> &#8211; usually in use in Debian, Ubuntu Linux.<\/li>\n<\/ul>\n<p>In case your system have more than one of them, then edit <code>.bash_profile<\/code> if exist, or <code>.bash_login<\/code>, and only use <code>.profile<\/code> when the previous 2 don&#8217;t exist. All the 3 usually tells to run <b>.bashrc<\/b>, so editing <code>.bashrc<\/code> also works.<\/p>\n<p><b>In Debian\/Ubuntu<\/b>, just open home folder, press Ctrl+H to show\/hide hidden files, and click edit the <b>.profile<\/b> file.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/local-profile.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47476\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/local-profile-700x363.webp\" alt=\"\" width=\"610\" height=\"316\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/local-profile-700x363.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/local-profile-300x156.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/local-profile-768x398.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/local-profile-1320x685.webp 1320w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/local-profile.webp 1452w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>When file opens, you&#8217;ll see something like this:<\/p>\n<pre>if [ -d \"$HOME\/bin\" ] ; then\r\n    PATH=\"$HOME\/bin:$PATH\"\r\nfi<\/pre>\n<p>It tells to add the <b>bin<\/b> folder if exist in user home to PATH. There&#8217;s also a section to add <b>.local\/bin<\/b> to PATH if exists.<\/p>\n<p>You can add custom folder into user&#8217;s PATH, by adding similar lines. For example, use lines below to add SweetHome3D v7.5 under MyApps sub-folder:<\/p>\n<pre>if [ -d \"$HOME\/MyApps\/SweetHome3D-7.5\" ] ; then\r\n    PATH=\"$HOME\/MyApps\/SweetHome3D-7.5:$PATH\"\r\nfi<\/pre>\n<p>Or, add the line below instead to add that folder to PATH whenever no matter if it exists or not.<\/p>\n<pre>export PATH=\"$HOME\/MyApps\/SweetHome3D-7.5:$PATH\"<\/pre>\n<p><b>To apply the change, you need to log out and back in. However, it does NOT work for non-login shell, e.g., <code>su user_name command<\/code>.<\/b><\/p>\n<h3>Option 2: Add PATH Variables system wide for all users<\/h3>\n<p>Debian and Ubuntu based systems use <code>\/etc\/environment<\/code> file to specify the original system-wide PATH variables. However, it&#8217;s NOT recommended to edit the file directly.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/etc-environment.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47477\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/etc-environment-700x260.webp\" alt=\"\" width=\"610\" height=\"227\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/etc-environment-700x260.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/etc-environment-300x111.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/etc-environment.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>Instead, <b>\/etc\/profile<\/b> or <code>.sh<\/code> files under <b>\/etc\/profile.d\/<\/b> directory are the correct places for adding system wide PATH variables.<\/p>\n<p>For example, edit the <code>\/etc\/profile<\/code> by running command:<\/p>\n<pre>sudo gnome-text-editor \/etc\/profile<\/pre>\n<p>Replace <code>gnome-text-editor<\/code> according to your desktop environment or use <code>nano<\/code> that works in most Linux. When file open, add new line in end:<\/p>\n<pre>export PATH=\"\/usr\/lib\/myapps\/bin:$PATH\"<\/pre>\n<p>After saving the file (For nano, press Ctrl+S to save then Ctrl+X to exit), <code>\/usr\/lib\/myapps\/bin<\/code> in the case will be added to PATH at next login.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/path-global.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47478\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/path-global-700x420.webp\" alt=\"\" width=\"610\" height=\"366\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/path-global-700x420.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/path-global-300x180.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/path-global-768x461.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/path-global.webp 999w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p><b>To keep <code>\/etc\/profile<\/code> clean<\/b>, it better to create custom <code>.sh<\/code> file under <code>\/etc\/profile.d<\/code> instead.<\/p>\n<p>For example, run command below to create a <code>custom_path_global.sh<\/code> file and edit it:<\/p>\n<pre>sudo gnome-text-editor \/etc\/profile.d\/custom_path_global.sh<\/pre>\n<p>Then, add the lines below will do the same job if the directory exists. And, it will be applied in next login:<\/p>\n<pre># Add custom PATH variables work for all users\r\nif [ -d \"\/usr\/lib\/myapps\/bin\" ] ; then\r\n    PATH=\"\/usr\/lib\/myapps\/bin:$PATH\"\r\nfi<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/path-global-script.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-47479\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/path-global-script-700x420.webp\" alt=\"\" width=\"610\" height=\"366\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/path-global-script-700x420.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/path-global-script-300x180.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/path-global-script-768x461.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/11\/path-global-script.webp 953w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>In the tutorial, I&#8217;ve taught how to add custom folder or directory into PATH variables in Ubuntu Linux.<\/p>\n<p>In short, user may run <code>export PATH=\"\/PATH\/TO\/CUSTOM\/FOLDER:$PATH\"<\/code> to add custom folder to PATH that works only in current terminal.<\/p>\n<p>Or, edit <code>.profile<\/code> for Debian\/Ubuntu or <code>.bash_profile<\/code> for Fedora, and add similar line that works at next login for current user only. While, editing <code>\/etc\/profile<\/code> or creating <code>.sh<\/code> file under <code>\/etc\/profile.d<\/code> can do the job system wide for all users.<\/p>","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to configure PATH environment variables. Though title said for Ubuntu 24.04, it works in most Linux systems. PATH specifies the directories in which the executable files of programs are located on the system. Without knowing or typing the full path to the file, just type the app name in the command [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":37909,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[19],"class_list":["post-47473","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-command-skill"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/47473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=47473"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/47473\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/37909"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=47473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=47473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=47473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}