Results 1 to 9 of 9

Thread: Help with adding to $PATH

  1. #1

    Default Help with adding to $PATH

    Machine# #2
    I am want to find out how to properly add ~/.local/bin to PATH.
    I need to do this in order to run a program from a bash [Konsole] terminal because the program resides in ~/.local/bin
    I have read a couple of articles on ways to do this but am unsure and don't want to mess anything.
    My current PATH is:
    Code:
    la@localhost:~> echo $PATH     
    /home/la/bin:/usr/local/bin:/usr/bin:/bin:/snap/bin 
    la@localhost:~>
    So if I want to add this to my PATH permanently I am supposed to open bashrc with an editor{nano??}
    and add the following line at the end of it. I note here that when I opened this
    ~/.bashrc file there was nothing in it.
    Code:
    export PATH="$HOME/bin:$PATH"
    What I am not sure of is: Do I just insert this line or do I have to substitute $HOME for .local?
    Code:
    export PATH=".local/bin:$PATH"
    Or is there another/better way to do this?
    Thank You.
    Machine # 1 - Asus Prime Z390A, i7-9700k 3.6GHz, 32.0 GB ram, Tumbleweed 64-bit, KDE Plasma 5.24.0
    Machine # 2 - Asus P8Z77-V Deluxe, i7-3770k 3.5GHz, 16.0 GB ram, Tumbleweed KDE Plasma 5.24.0

  2. #2
    Join Date
    Aug 2010
    Location
    Chicago suburbs
    Posts
    16,047
    Blog Entries
    3

    Default Re: Help with adding to $PATH

    Quote Originally Posted by LaQuirrELL View Post
    What I am not sure of is: Do I just insert this line or do I have to substitute $HOME for .local?
    Code:
    export PATH=".local/bin:$PATH"
    Try:
    Code:
    export PATH="$HOME/.local/bin:$PATH"
    openSUSE Leap 15.4; KDE Plasma 5.24.4;
    testing Tumbleweed.

  3. #3
    Join Date
    Jan 2014
    Location
    Erlangen
    Posts
    4,167
    Blog Entries
    2

    Default Re: Help with adding to $PATH

    Quote Originally Posted by LaQuirrELL View Post
    Machine# #2
    I am want to find out how to properly add ~/.local/bin to PATH.
    I need to do this in order to run a program from a bash [Konsole] terminal because the program resides in ~/.local/bin
    I have read a couple of articles on ways to do this but am unsure and don't want to mess anything.
    My current PATH is:
    Code:
    la@localhost:~> echo $PATH     
    /home/la/bin:/usr/local/bin:/usr/bin:/bin:/snap/bin 
    la@localhost:~>
    So if I want to add this to my PATH permanently I am supposed to open bashrc with an editor{nano??}
    and add the following line at the end of it. I note here that when I opened this
    ~/.bashrc file there was nothing in it.
    Code:
    export PATH="$HOME/bin:$PATH"
    What I am not sure of is: Do I just insert this line or do I have to substitute $HOME for .local?
    Code:
    export PATH=".local/bin:$PATH"
    Or is there another/better way to do this?
    Thank You.
    Note this section of /etc/profile:
    Code:
    # 
    # Make path more comfortable 
    # 
    # save current path setting, we might want to restore it 
    ORIG_PATH=$PATH 
    # 
    if test -z "$PROFILEREAD" ; then 
        PATH=/usr/local/bin:/usr/bin:/bin 
        if test "$HOME" != "/" ; then 
            for dir in $HOME/bin/$CPU $HOME/bin $HOME/.local/bin/$CPU $HOME/.local/bin ; do 
                test -d $dir && PATH=$dir:$PATH 
            done 
        fi 
        if test "$UID" = 0 ; then 
            test -d /opt/kde3/sbin  && PATH=/opt/kde3/sbin:$PATH 
            PATH=/sbin:/usr/sbin:/usr/local/sbin:$PATH 
        fi 
        for dir in  /usr/X11/bin \ 
                    /usr/X11R6/bin \ 
                    /var/lib/dosemu \ 
                    /usr/games \ 
                    /opt/bin \ 
                    /opt/kde3/bin \ 
                    /opt/kde2/bin \ 
                    /opt/kde/bin \ 
                    /usr/openwin/bin \ 
                    /opt/cross/bin 
        do 
            test -d $dir && PATH=$PATH:$dir 
        done 
        unset dir 
        export PATH 
    fi
    Creating $HOME/.local/bin will automatically prepend the directory to PATH on next login:
    Code:
    karl@i3-4130:~> echo $PATH 
    /home/karl/.local/bin:/home/karl/bin:/usr/local/bin:/usr/bin:/bin 
    karl@i3-4130:~> 
    i7-6700K (2016), i5-8250U (2018), AMD Ryzen 5 3400G (2020), 5600X, 5700U (2022) openSUSE Tumbleweed, KDE Plasma

  4. #4
    Join Date
    Feb 2010
    Location
    Germany
    Posts
    5,039

    Default Re: Help with adding to $PATH

    Quote Originally Posted by LaQuirrELL View Post
    So if I want to add this to my PATH permanently I am supposed to open bashrc with an editor{nano??}
    The main issue with the PATH variable is, it ain't only used by “bash” – it's used by every other shell as well plus, some Desktop Environments.
    • Therefore, do not set the PATH variable in the ~/.bashrc file.

    The system-wide setting of the PATH variable is done in the /etc/profile file – if you do not wish to believe me, “grep” for PATH in /etc …

    • Therefore, simply follow the system-wide method and, set any user specific modifications needed to the PATH variable in the user's ~/.profile file.


    Editor to use –
    • Short answer, any text editor.
    • Command line – “vim” or, “ex” or, “ed” or, EMACS or, whatever
    • Desktop Environment – simply click on the configuration file – the default text editor will, normally, start and, open the file for editing:
    • If KDE Plasma then, “Kate”.
    • If GNOME then, “gedit”.
    • If something else then, whatever that Desktop Environment has as a default text editor.


    And, if you want to append you private Path to the PATH variable – as opposed to prepending «as in attaching as a prefix» your private Path to the PATH variable, then, you have to use the following syntax:
    Code:
    export PATH=${PATH}:"$HOME/.local/bin"

    Why make it complex when, it's so simple?
    • Even that thing out of Redmond normally opens text files for editing if, you «double» click on the file …

  5. #5
    Join Date
    Apr 2011
    Location
    Texas USA
    Posts
    519

    Default Re: Help with adding to $PATH

    If your system is multi-user, i.e., others using system and doing different things, I would add the amended PATH statement to the user ~/.bashrc file rather than the system profile file. Changing PATH in /etc makes it universal fror all users. This could upset executible searches that other users are doing for their searches. Each user has its own ~/.bashrc file that is run upon login for that user or when a user runs "source" command. Put their personal PATH needs in ~/.bashrc.

    If it is a single user system, it makes no difference where you put the amended PATH statement.

    tom kosvic

  6. #6
    Join Date
    Jun 2008
    Location
    East of Podunk
    Posts
    33,373
    Blog Entries
    15

    Default Re: Help with adding to $PATH

    Quote Originally Posted by tckosvic View Post
    If your system is multi-user, i.e., others using system and doing different things, I would add the amended PATH statement to the user ~/.bashrc file rather than the system profile file. Changing PATH in /etc makes it universal fror all users. This could upset executible searches that other users are doing for their searches. Each user has its own ~/.bashrc file that is run upon login for that user or when a user runs "source" command. Put their personal PATH needs in ~/.bashrc.

    If it is a single user system, it makes no difference where you put the amended PATH statement.

    tom kosvic
    Hi Tom
    There is nothing to do, if the directory exists for $USER, the openSUSE default /etc/profile checks for this directory ~/.local/bin and will add to $PATH.
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

  7. #7

    Default Re: Help with adding to $PATH

    Quote Originally Posted by dcurtisfra View Post
    And, if you want to append you private Path to the PATH variable – as opposed to prepending «as in attaching as a prefix» your private Path to the PATH variable, then, you have to use the following syntax:
    Code:
    export PATH=${PATH}:"$HOME/.local/bin"
    Jumping on the thread here:
    I have done exactly this to my ~/.bashrc (I am the only user) and when I echo $PATH after reboot I get my newly defined path appended twice. How do I append it only once?

    BR

  8. #8
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    31,293

    Default Re: Help with adding to $PATH

    Because bash.rc is added at every bash start. So start from a bash will ad it again and again.
    It should be in you users .profile
    Henk van Velden

  9. #9

    Default Re: Help with adding to $PATH

    Quote Originally Posted by hcvv View Post
    Because bash.rc is added at every bash start. So start from a bash will ad it again and again.
    It should be in you users .profile
    Thanks very much, that has worked for me!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •