Linux 101: How to add directories to your Linux $PATH

At some point, you’re going to want to run commands from non-standard directories. When that happens, you’ll want to add those directories to your $PATH. Jack Wallen shows you how.

Linux logo in purple

Image: PegasuStudio/Shutterstock

Your Linux PATH is how you define the directories for which commands can be run globally. In other words, if you have an executable file in a directory that is configured to be in your PATH, you can run that executable from anywhere in the Linux file structure. This is what makes it possible 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 happens if you have a non-standard directory from which you need to be able to execute commands? That’s when you have to manually add those directories to the PATH. 

How do you do that? Let me show you. 
Let’s say you have a directory called SCRIPTS in your home directory. Let’s add that to the PATH. 

  1. Log into your Linux machine and open a terminal window. 
  2. Open your .bashrc file for editing with the command nano ~/.bashrc
  3. Scroll to the bottom of that file and add the following: PATH=”~/SCRIPTS:$PATH”.
    It’s very important to include the $PATH portion, as that makes sure the standard directories remain in your path (otherwise, the only directory in your PATH would be SCRIPTS and that would not be good). 
  4. Save and close the file. 
  5. Close and reopen the terminal. 

At this point, you can run any executable, found in the SCRIPTS directory, from anywhere in the filesystem 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 very handy, especially when you start writing your own bash scripts that you don’t want to be saved in common directories.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.

Also see

Stay connected with us on social media platform for instant update click here to join our  Twitter, & Facebook

We are now on Telegram. Click here to join our channel (@TechiUpdate) and stay updated with the latest Technology headlines.

For all the latest Technology News Click Here 

 For the latest news and updates, follow us on Google News

Read original article here

Denial of responsibility! TechiLive.in is an automatic aggregator around the global media. All the content are available free on Internet. We have just arranged it in one platform for educational purpose only. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials on our website, please contact us by email – [email protected]. The content will be deleted within 24 hours.