Linux 101: How to add directories to your Linux $ PATH
[ad_1]
At some point, you’ll want to run commands from non-standard directories. When that happens, you’ll want to add these directories to your $ PATH. Jack Wallen shows you how.
Image: PegasuStudio / Shutterstock
Your Linux PATH is how you define the directories for which commands can be executed globally. In other words, if you have an executable file in a directory configured to be in your PATH, you can run that executable from anywhere in the Linux file structure. This is what allows you to run commands in / usr / bin from your home directory (or anywhere, for that matter).
SEE: 5 Linux Server Distributions You Should Be Using (TechRepublic Premium)
Out of the box, the Linux PATH contains the usual entries, such as / usr / bin /, / usr / sbin /, / usr / local / bin, and so on. But what if you have a non-standard directory from which you need to be able to run commands? This is when you need to manually add these directories to the PATH.
How are you doing that? Let me show you.
Let’s say you have a directory called SCRIPTS in your home directory. Let’s add this to the PATH.
- Log into your Linux machine and open a terminal window.
- Open your .bashrc file to edit it with the command nano ~ / .bashrc.
- Scroll to the bottom of this file and add the following: PATH = “~ / SCRIPTS: $ PATH”.
It is very important to include the $ PATH part, as this ensures that the standard directories stay in your path (otherwise the only directory in your PATH would be SCRIPTS and that would not be good). - Save and close the file.
- Close and reopen the terminal.
At this point, you can run any executable, found in the SCRIPTS directory, from anywhere in the file system hierarchy.
SEE: Rust: What Developers Need To Know About This Programming Language (Free PDF) (TechRepublic)
And that’s how you add new directories to your PATH. This little trick will come in handy, especially when you start to write your own bash scripts that you don’t want to save in common directories.
Subscribe to TechRepublic How to make technology work on YouTube for all the latest technical advice for professionals at Jack Wallen’s business.
Also look
[ad_2]