{"id":22085,"date":"2023-10-01T16:18:10","date_gmt":"2023-10-01T16:18:10","guid":{"rendered":"https:\/\/linuxways.net\/?p=22085"},"modified":"2023-10-01T16:18:10","modified_gmt":"2023-10-01T16:18:10","slug":"how-to-add-a-directory-to-a-path-in-linux-ubuntu","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-add-a-directory-to-a-path-in-linux-ubuntu\/","title":{"rendered":"How to Add a Directory to a $PATH in Linux\/Ubuntu?"},"content":{"rendered":"<p>A <strong>path<\/strong> in an <strong>environment variable <\/strong>that includes directories such as <strong>bin<\/strong>, <strong>sbin<\/strong>, etc. These directories contain executable files. A path guides the <strong>Linux\/Ubuntu shell<\/strong> where to look for executable files. This enables a user to execute a command from anywhere in the system without stating the path provided that the <strong>directory <\/strong>is added to the<strong> $PATH<\/strong>.<\/p>\n<p>This article will demonstrate how to add and remove a directory to and from a $PATH on Linux\/Ubuntu 22.04 LTS. This article will discuss:<\/p>\n<ul>\n<li>How to View Configured Directories in $Path?<\/li>\n<li>How to Search the Path of an Executable in Linux\/Ubuntu?<\/li>\n<li>How to Add\/Include a Directory to Path via Terminal?<\/li>\n<li>How to Add\/Include a Directory to the Path by Modifying .bashrc File?<\/li>\n<li>How to Add\/Include a Directory to the Path by Modifying .profile File?<\/li>\n<li>How to Add\/Include a Directory to the Path by Modifying the\/etc\/environment File?<\/li>\n<li>How to Remove\/Delete a Directory from Path via Terminal?<\/li>\n<li>How to Remove\/Delete a Directory from Path via grep, Paste, and tr Utilities?<\/li>\n<li>How to Remove\/Delete a Directory from Path by Editing .bashrc, .profile, and \/etc\/environment Files?<\/li>\n<li>How to Remove\/Delete a Directory from Path by String Replacement?<\/li>\n<\/ul>\n<h2><a id=\"post-22085-_su5p0o25o4ha\"><\/a>How to View Configured Directories in $Path?<\/h2>\n<p>The configured directories in the Linux\/Ubuntu system can be displayed by <strong>echo <\/strong>by<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw3\">echo<\/span> <span class=\"re1\">$PATH<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"240\" class=\"wp-image-22098\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-1.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-1-300x35.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-1-1024x120.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-1-768x90.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-1-1536x180.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>Alternatively, the configured directories can also be displayed by using <strong>printenv <\/strong>commands as follows:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span>printenv PATH<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"212\" class=\"wp-image-22107\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-2.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-2-300x31.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-2-1024x106.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-2-768x80.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-2-1536x159.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<h2><a id=\"post-22085-_9v9jzhgbhvhu\"><\/a>How to Search the Path of an Executable in Linux\/Ubuntu?<\/h2>\n<p>The path of executables can be seared by using <strong>which <\/strong>command. The following commands display the paths of <strong>echo <\/strong>and <strong>apt <\/strong>command line utilities.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">$ <span class=\"kw2\">which<\/span> <span class=\"kw3\">echo<\/span><br \/>\n<br \/>\n$ <span class=\"kw2\">which<\/span> apt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"346\" class=\"wp-image-22120\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-3.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-3-300x51.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-3-1024x173.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-3-768x130.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-3-1536x260.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be observed that echo and apt paths are <strong>\/usr\/bin\/echo<\/strong> and <strong>\/usr\/bin\/apt <\/strong>respectively.<\/p>\n<h2><a id=\"post-22085-_94o3vcspj1pt\"><\/a>How to Add\/Include a Directory to Path via Terminal?<\/h2>\n<p>A directory is temporarily added to $PATH via Terminal by the following syntax:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw3\">export<\/span> <span class=\"re2\">PATH<\/span>=<span class=\"st0\">&quot;&lt;Directory&gt;:<span class=\"es2\">$PATH<\/span>&quot;<\/span><\/div><\/div>\n<p>For example if we want to add directory <strong>\/home\/linuxuser\/test\/path, <\/strong>the following command will be used:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw3\">export<\/span> <span class=\"re2\">PATH<\/span>=<span class=\"st0\">&quot;<span class=\"es2\">$HOME<\/span>\/test\/path:<span class=\"es2\">$PATH<\/span>&quot;<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"118\" class=\"wp-image-22129\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-4.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-4-300x17.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-4-1024x59.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-4-768x44.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-4-1536x89.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>We can verify the added directory by<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw3\">echo<\/span> <span class=\"re1\">$PATH<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"206\" class=\"wp-image-22137\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-5.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-5-300x30.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-5-1024x103.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-5-768x77.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-5-1536x155.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be observed that the path is successfully added. Additionally, these changes in the path are temporary and will only be in effect for the current terminal session.<\/p>\n<h2><a id=\"post-22085-_6p5y6kv9yo1n\"><\/a>How to Add\/Include a Directory to Path by Modifying .bashrc File?<\/h2>\n<p>The following steps are followed to add a directory: <strong> \/home\/linuxuser\/test\/path<\/strong> to a path <strong>permanently<\/strong>:<\/p>\n<ul>\n<li>Open the \u201c<strong>.bashrc\u201d <\/strong>file in a Nano Text Editor:<\/li>\n<\/ul>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">nano<\/span> .bashrc<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"123\" class=\"wp-image-22142\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-6.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-6-300x18.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-6-1024x62.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-6-768x46.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-6-1536x92.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<ul>\n<li>Scroll to the end of the file and insert the following line:<\/li>\n<\/ul>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw3\">export<\/span> <span class=\"re2\">PATH<\/span>=<span class=\"st0\">&quot;<span class=\"es2\">$HOME<\/span>\/test\/path:<span class=\"es2\">$PATH<\/span>&quot;<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1238\" class=\"wp-image-22155\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-7.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-7-300x181.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-7-1024x619.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-7-768x464.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-7-1536x929.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<ul>\n<li>Save and Exit .bashrc file by pressing [Ctrl+O] and [Ctrl+X] respectively.<\/li>\n<li>Reboot the system or run the following script for the changes to take effect immediately:<\/li>\n<\/ul>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw3\">source<\/span> ~<span class=\"sy0\">\/<\/span>.bashrc<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"105\" class=\"wp-image-22157\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-8.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-8-300x15.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-8-1024x53.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-8-768x39.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-8-1536x79.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<ul>\n<li>The addition of Directory<strong> \/home\/linuxuser\/test\/path <\/strong>can be verified by<strong> echo <\/strong>command by<\/li>\n<\/ul>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw3\">echo<\/span> <span class=\"re1\">$PATH<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"206\" class=\"wp-image-22162\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-9.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-9.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-9-300x30.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-9-1024x103.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-9-768x77.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-9-1536x155.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The above image confirms that the desired directory is added to $PATH. Additionally, a directory is added for current users only by modifying the .bashrc file.<\/p>\n<h2><a id=\"post-22085-_elknxnv6e1l4\"><\/a>How to Add\/Include a Directory to Path by Modifying .profile File?<\/h2>\n<p>The following steps are followed to add a directory: <strong> \/home\/linuxuser\/test\/path<\/strong> <strong>permanently <\/strong>by modifying the <strong>.profile <\/strong>file.<\/p>\n<ul>\n<li>Open the \u201c<strong>.profile\u201d <\/strong>file in Text Editor, for example, Nano text editor:<\/li>\n<\/ul>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">nano<\/span> .profile<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"170\" class=\"wp-image-22167\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-10.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-10.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-10-300x25.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-10-1024x85.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-10-768x64.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-10-1536x128.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<ul>\n<li>Scroll to the end of the file and insert the following line:<\/li>\n<\/ul>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw3\">export<\/span> <span class=\"re2\">PATH<\/span>=<span class=\"st0\">&quot;<span class=\"es2\">$HOME<\/span>\/test\/path:<span class=\"es2\">$PATH<\/span>&quot;<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1236\" class=\"wp-image-22171\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-11.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-11.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-11-300x181.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-11-1024x618.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-11-768x464.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-11-1536x927.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<ul>\n<li>Save and Exit .profile file by pressing [Ctrl+O] and [Ctrl+X] respectively.<\/li>\n<li>Reboot the system in order for the changes to be in effect.<\/li>\n<li>The addition of Directory<strong> \/home\/linuxuser\/test\/path <\/strong>can be verified by<strong> echo <\/strong>command by<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"206\" class=\"wp-image-22174\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-12.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-12.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-12-300x30.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-12-1024x103.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-12-768x77.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-12-1536x155.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The above image confirms that the desired directory is added to $PATH. Additionally, a directory is added for all users only by modifying the .profile file.<\/p>\n<h2><a id=\"post-22085-_nyx4mu1e4all\"><\/a>How to Add\/Include a Directory to Path by Modifying \/etc\/environment File?<\/h2>\n<p>The following steps are followed to add a directory: <strong> \/home\/linuxuser\/test\/path<\/strong> <strong>permanently<\/strong> by modifying the <strong>\/etc\/environment <\/strong>file.<\/p>\n<ul>\n<li>Open the \u201c<strong>\/etc\/environment\u201d <\/strong>file in Text Editor, for example, Nano text editor:<\/li>\n<\/ul>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">nano<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>environment<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"120\" class=\"wp-image-22177\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-13.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-13.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-13-300x18.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-13-1024x60.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-13-768x45.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-13-1536x90.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<ul>\n<li>Add the following line at the end of the file.<\/li>\n<\/ul>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"re2\">PATH<\/span>=<span class=\"st0\">&quot;PATH\/home\/linuxuser\/test\/path&quot;<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1242\" class=\"wp-image-22180\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-14.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-14.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-14-300x182.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-14-1024x621.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-14-768x466.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-14-1536x932.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<ul>\n<li>Save and Exit .profile file by pressing [Ctrl+O] and [Ctrl+X] respectively.<\/li>\n<li>Reboot the system in order for the changes to be in effect.<\/li>\n<li>The addition of Directory<strong> \/home\/linuxuser\/test\/path <\/strong>can be verified by<strong> echo <\/strong>command by<\/li>\n<\/ul>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw3\">echo<\/span> <span class=\"re1\">$PATH<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"206\" class=\"wp-image-22182\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-15.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-15.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-15-300x30.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-15-1024x103.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-15-768x77.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-15-1536x155.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The above image confirms that the desired directory is added to $PATH. Additionally, modifying the \u201c<strong>\/etc\/environment\u201d <\/strong>file sets system-wide environment variables.<\/p>\n<h2><a id=\"post-22085-_hwql6dhsy91j\"><\/a>How to Remove\/Delete a Directory from Path via Terminal?<\/h2>\n<p>If the directory is added using <strong>export PATH=&#8221;&lt;Directory&gt;:$PATH&#8221; <\/strong>then these changes are temporary and will no longer exist after the terminal is restarted.<\/p>\n<h2><a id=\"post-22085-_j92jbnfzr0r0\"><\/a>How to Remove\/Delete a Directory from Path via grep, Paste, and tr Utilities?<\/h2>\n<p>A directory \u201c\/home\/linuxuser\/test\/path\u201d is removed from $PATH by using a combination of tr, grep, and paste Command by<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw3\">export<\/span> <span class=\"re2\">PATH<\/span>=<span class=\"st0\">&quot;<span class=\"es4\">$( echo $PATH| tr : '\\n' |grep -v $HOME\/test\/path | paste -s -d: )<\/span>&quot;<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"613\" class=\"wp-image-22186\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-16.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-16.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-16-300x90.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-16-1024x307.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-16-768x230.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-16-1536x460.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The above image confirms that the directory \u201c\/home\/linuxuser\/test\/path\u201d is removed from the $PATH.<\/p>\n<h2><a id=\"post-22085-_9tz9ekr359oh\"><\/a>How to Remove\/Delete a Directory from Path by Editing .bashrc, .profile, and \/etc\/environment Files?<\/h2>\n<p>A directory can be permanently removed from $PATH by modifying the .bashrc, .profile, and \/etc\/environment Files. For example, if we have to remove a directory \u201c\/home\/linuxuser\/test\/path\u201d, we can edit .bashrc and .profile files by:<\/p>\n<ul>\n<li>Scrolling to the end of the files and removing the line below:<\/li>\n<\/ul>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"re2\">PATH<\/span>=<span class=\"st0\">&quot;PATH\/home\/linuxuser\/test\/path&quot;<\/span><\/div><\/div>\n<p>Additionally, if we have to remove a directory \u201c\/home\/linuxuser\/test\/path\u201d, we can edit \/etc\/environment file by:<\/p>\n<ul>\n<li>Remove the following line at the end of the file<\/li>\n<\/ul>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"re2\">PATH<\/span>=<span class=\"st0\">&quot;PATH\/home\/linuxuser\/test\/path&quot;<\/span><\/div><\/div>\n<ul>\n<li>Save and Exit .bashrc, .profile, and edit \/etc\/environment files by pressing [Ctrl+O] and [Ctrl+X] respectively.<\/li>\n<li>Reboot the system in order for the changes to be in effect.<\/li>\n<\/ul>\n<h2><a id=\"post-22085-_wtovo6jlyu7h\"><\/a>How to Remove\/Delete a Directory from Path by String Replacement?<\/h2>\n<p>String Replacement can be used to remove a directory \u201c\/home\/linuxuser\/test\/path\u201d from $PATH by<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw3\">export<\/span> <span class=\"re2\">PATH<\/span>=<span class=\"co1\">${PATH\/'\/home\/linuxuser\/test\/path'\/}<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"507\" class=\"wp-image-22190\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-17.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-17.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-17-300x74.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-17-1024x254.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-17-768x190.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22085-17-1536x380.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The above image confirms that the directory \u201c\/home\/linuxuser\/test\/path\u201d is removed from the $PATH.<\/p>\n<h2><a id=\"post-22085-_k4r3ojha6hv3\"><\/a>Conclusion<\/h2>\n<p>A directory is added to a $PATH permanently by modifying either of the three fiels:<strong>.bashrc file<\/strong>, <strong>.profile file, <\/strong>and <strong>\/etc\/environment file<\/strong>. Additionally, a directory is added to a $PATH temporarily by using the command <strong>\u201cexport PATH=&#8221;&lt;directorypath&gt;:$PATH&#8221;<\/strong>. This article demonstrated how to add a directory temporarily and permanently to $PATH as well as how to remove a directory on Linux\/Ubuntu 22.04 LTS.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>A directory is added to a $PATH permanently by modifying either the .bashrc file or .profile file \/etc\/environment file.<\/p>","protected":false},"author":110,"featured_media":22196,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049,2],"tags":[],"class_list":["post-22085","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22085","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=22085"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22085\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/22196"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=22085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=22085"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=22085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}