• How to Add a Directory to PATH in Linux

    From Black Panther@77:1/102 to All on Tue Jul 30 22:38:26 2019
    https://linuxize.com/post/how-to-add-directory-to-path-in-linux/

    When you type a command on the command line, you're basically telling the
    shell to run an executable file with the given name. In Linux these
    executable programs like ls, find, file and others, usually live inside
    several different directories on your system. Any file with executable permissions stored in these directories can be run from any location. The
    most common directories that hold executable programs are /bin, /sbin, /usr/sbin, /usr/local/bin and / usr/local/sbin.

    But how does the shell knows, what directories to search for executable programs or does the shell search through the whole filesystem?

    The answer is simple. When you type a command, the shell searches through all directories specified in the user $PATH variable for an executable file of that name.

    This article shows how to add directories to your $PATH in Linux systems.
    What is $PATH in Linux

    The $PATH environmental variable is a colon-delimited list of directories that tells the shell which directories to search for executable files.

    To check what directories are in your $PATH, you can use either the printenv or echo command:

    echo $PATH

    The output will look something like this:

    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:
    /usr/local/games:/snap/bin

    If you have two executable files sharing the same name located in two different directories the shell will run the file that lives in the directory which comes first in the $PATH.

    Adding a Directory to your $PATH

    There are situations where you may want to add other directories the $PATH variable. For example, some programs may be installed in different locations or you may want to have a dedicated directory for your personal scrips, but be able to run them without specifying the absolute path to the executable files. To do this you simply need to add the directory to your $PATH.

    Let's say you have a directory called bin located in your Home directory in which you keep your shell scripts. To add the directory to your $PATH type in:

    export PATH="$HOME/bin:$PATH"

    The export command will export the modified variable to the shell child process environments.

    You can now run your scripts simply by typing the executable script name without needing to specify the executable full path.

    However, this change is only temporary and valid only in the current shell session.

    To make the change permanent, you need to define the $PATH variable in the shell configuration files. In most Linux distributions when you start a new session, environment variables are read from the following files:

    - Global shell specific configuration files such as /etc/environment and /etc/ profile. Use this file if you want the new directory to be added to all system users $PATH.

    - Per-user shell specific configuration files. For example, if you are using Bash, you can set the $PATH variable in the ~/.bashrc file and if you are using Zsh the file name is ~/.zshrc.

    In this example, we'll set the variable in the ~/.bashrc file. Open the file with your text editor and add the following line at the end of it:

    nano ~/.bashrc

    export PATH="$HOME/bin:$PATH"

    Save the file and load the new $PATH into the current shell session using the source command:

    source ~/.bashrc

    To confirm that the directory was successfully added, print the value of your $PATH by typing:

    echo $PATH

    Conclusion

    Adding new directories to your user or global $PATH variable is pretty simple. This allows you execute commands and scripts stored on nonstandard locations without needing to type the full path to the executable.

    The same instructions apply for any Linux distribution, including Ubuntu, CentOS, RHEL, Debian and Linux Mint.


    ---

    |03B|09lack |03P|09anther|03(|09RCS|03)|07

    --- Mystic BBS v1.12 A43 2019/03/02 (Linux/64)
    * Origin: Castle Rock BBS - bbs.castlerockbbs.com - (77:1/102)
  • From Netsurge@77:1/100 to Black Panther on Wed Jul 31 00:54:22 2019
    Save the file and load the new $PATH into the current shell session
    using the source command:

    source ~/.bashrc

    I have always added things to my path via /etc/profile

    |15frank |08// |15netsurge
    |07disksh0p|08!|07bbs |08% |07bbs.diskshop.ca |08% |07mystic goodness |11SciNet |03ftn hq |08% |07https://diskshop.ca/scinet

    --- Mystic BBS v1.12 A43 2019/03/02 (Linux/64)
    * Origin: % disksh0p!bbs % bbs.diskshop.ca % SciNet ftn hq % (77:1/100)
  • From Black Panther@77:1/102 to Netsurge on Tue Jul 30 23:13:28 2019
    On 31 Jul 2019, Netsurge said the following...

    source ~/.bashrc

    I have always added things to my path via /etc/profile

    I've used ~/.bashrc, because that was the first way I found when looking it
    up online... ;)

    I hope it alright if I post random articles like this. If I would have had
    this information when I started with Linux, it would have made life a lot easier for me... :)

    There might be someone looking into trying Linux, and these might help them out.


    ---

    |03B|09lack |03P|09anther|03(|09RCS|03)|07

    --- Mystic BBS v1.12 A43 2019/03/02 (Linux/64)
    * Origin: Castle Rock BBS - bbs.castlerockbbs.com - (77:1/102)
  • From Netsurge@77:1/100 to Black Panther on Wed Jul 31 02:08:30 2019
    I hope it alright if I post random articles like this. If I would have
    had this information when I started with Linux, it would have made life
    a lot easier for me... :)

    Of course. I'm all about the learning, lol.

    |15frank |08// |15netsurge
    |07disksh0p|08!|07bbs |08% |07bbs.diskshop.ca |08% |07mystic goodness |11SciNet |03ftn hq |08% |07https://diskshop.ca/scinet

    --- Mystic BBS v1.12 A43 2019/03/02 (Linux/64)
    * Origin: % disksh0p!bbs % bbs.diskshop.ca % SciNet ftn hq % (77:1/100)
  • From Gamgee@77:1/114 to Netsurge on Wed Jul 31 07:47:00 2019
    Netsurge wrote to Black Panther <=-

    Save the file and load the new $PATH into the current shell session
    using the source command:

    source ~/.bashrc

    I have always added things to my path via /etc/profile

    Nothing wrong with that, except that it now applies to all users
    that may be on the system. For user-specific paths (such as /home/netsurge/scripts/ or similar), it's probably better to use
    the /home/netsurge/.bashrc file to define the path.



    ... If it weren't for Edison we'd be using computers by candlelight
    === MultiMail/Linux v0.52
    --- SBBSecho 3.07-Linux
    * Origin: Palantir * palantirbbs.ddns.net * Pensacola, FL * (77:1/114)
  • From Netsurge@77:1/100 to Gamgee on Wed Jul 31 10:34:06 2019
    Nothing wrong with that, except that it now applies to all users
    that may be on the system. For user-specific paths (such as /home/netsurge/scripts/ or similar), it's probably better to use
    the /home/netsurge/.bashrc file to define the path.

    You are correct, but none of my systems are used by multiple users. At work, all the systems tend to be single purpose production machines.

    |15frank |08// |15netsurge
    |07disksh0p|08!|07bbs |08% |07bbs.diskshop.ca |08% |07mystic goodness |11SciNet |03ftn hq |08% |07https://diskshop.ca/scinet

    --- Mystic BBS v1.12 A43 2019/03/02 (Linux/64)
    * Origin: % disksh0p!bbs % bbs.diskshop.ca % SciNet ftn hq % (77:1/100)