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

3 years ago 493

At immoderate point, you're going to privation to tally commands from non-standard directories. When that happens, you'll privation to adhd those directories to your $PATH. Jack Wallen shows you how.

Linux logo successful  purple

Image: PegasuStudio/Shutterstock

Your Linux PATH is however you specify the directories for which commands tin beryllium tally globally. In different words, if you person an executable record successful a directory that is configured to beryllium successful your PATH, you tin tally that executable from anyplace successful the Linux record structure. This is what makes it imaginable to tally commands successful /usr/bin from your location directory (or anywhere, for that matter). 

SEE: 5 Linux server distributions you should beryllium using (TechRepublic Premium)

Out of the box, the Linux PATH contains the accustomed entries, specified arsenic /usr/bin/, /usr/sbin/, /usr/local/bin, and truthful on. But what happens if you person a non-standard directory from which you request to beryllium capable to execute commands? That's erstwhile you person to manually adhd those directories to the PATH. 

How bash you bash that? Let maine amusement you. 
Let's accidental you person a directory called SCRIPTS successful your location directory. Let's adhd that to the PATH. 

  1. Log into your Linux instrumentality and unfastened a terminal window. 
  2. Open your .bashrc record for editing with the bid nano ~/.bashrc
  3. Scroll to the bottommost of that record and adhd the following: PATH="~/SCRIPTS:$PATH".
    It's precise important to see the $PATH portion, arsenic that makes definite the modular directories stay successful your way (otherwise, the lone directory successful your PATH would beryllium SCRIPTS and that would not beryllium good). 
  4. Save and adjacent the file. 
  5. Close and reopen the terminal. 

At this point, you tin tally immoderate executable, recovered successful the SCRIPTS directory, from anyplace successful the filesystem hierarchy. 

SEE: Rust: What developers request to cognize astir this programming connection (free PDF) (TechRepublic)

And that's however you adhd caller directories to your PATH. This small instrumentality volition travel successful precise handy, particularly erstwhile you commencement penning your ain bash scripts that you don't privation to beryllium saved successful communal directories.

Open Source Weekly Newsletter

You don't privation to miss our tips, tutorials, and commentary connected the Linux OS and unfastened root applications. Delivered Tuesdays

Sign up today

Also see

Read Entire Article