You are not logged in.

#1 2023-07-23 11:37:07

860lacov
Member
Registered: 2020-05-02
Posts: 497

Where is the configuration for the $PATH variable stored?

I use Arch Linux with KDE Plasma. I would like to add the directory /home/jm/bin to the $PATH variable. I know I can add "export PATH="${PATH}:/home/jm/bin"" at the end of the .bashrc file, but it occurred to me to manually add the /home/jm/bin path to the configuration file. I checked everything that came to my mind, such as etc/bash.bashrc, but I can't find the configuration for the $PATH variable, which currently looks like this:

/usr/local/sbin:/usr/local/bin:/usr/bin:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl

Defining variables didn't help.

Offline

#2 2023-07-23 11:46:41

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,111

Re: Where is the configuration for the $PATH variable stored?

The systemwide $PATH is setup in /etc/profile .

You typically DON'T add user-specific search folders there


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#3 2023-07-23 12:19:47

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,466
Website

Re: Where is the configuration for the $PATH variable stored?

It's an environment variable.  It's carried in memory (the environment) of every running process.  There is no file in which it is stored*.  It can be set / appeneded to in any script file that is sourced / executed as outlined in the link you posted.

There are, however, some good (and not so good) practices of where to set / export it.  Your ~/.bashrc is generally not a good place to set / export PATH; your ~/.bash_profile is.  (This too is covered in the wiki page you linked to.)

*note: technically this chunk of the processes memory is represented by a pseudo-file at /proc/$PID/environ, but these cannot be edited to change the PATH variable - and even if they could it would only change it for that running process.

Last edited by Trilby (2023-07-23 12:23:28)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2023-07-23 13:04:47

860lacov
Member
Registered: 2020-05-02
Posts: 497

Re: Where is the configuration for the $PATH variable stored?

Thank you.
My current cat bash_profile  output is:

$ cat .bash_profile 
#
# ~/.bash_profile
#

[[ -f ~/.bashrc ]] && . ~/.bashrc

Should I just change it to:

#
# ~/.bash_profile
#

[[ -f ~/.bashrc ]] && . ~/.bashrc
export PATH="${PATH}:/home/jm/bin"

?

Offline

#5 2023-07-23 13:13:51

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,466
Website

Re: Where is the configuration for the $PATH variable stored?

If that variable is used from anything in .bashrc (or from anything called from within .bashrc) it would have to be first.  And even if this isn't the case, now, it'd be far better practice to set / export the variable first in order to avoid future surprises:

export PATH="${PATH}:/home/jm/bin"
[[ -f ~/.bashrc ]] && . ~/.bashrc

But if you are using a display manager, be sure to see the comments about that in the wiki page.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#6 2023-07-23 13:15:23

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,129

Re: Where is the configuration for the $PATH variable stored?

That will cover bash's but not necessariy other shells.
Sth. like

if [ -d ~/bin ] ; then
    PATH=$HOME/bin:"${PATH}"
fi

in ~/.profile would be more common, also nb. the order which will allow you to shadow global executables in ~/bin

Edit: fckagain.

Last edited by seth (2023-07-23 13:16:08)

Offline

#7 2023-07-24 05:18:03

Ferdinand
Member
From: Norway
Registered: 2020-01-02
Posts: 338

Re: Where is the configuration for the $PATH variable stored?

Just as a general comment, I found it to be an enlightening process to trace the configurations files, or startup scripts, involved in starting my shell; it helps understand how things fit together and makes it clearer where to put customizations.

I use Bash, Xfce and Lightdm, and there's a truckload of places to add stuff during startup, but basically it goes like this:

/etc/lightdm/Xsession
    /etc/profile
        /etc/profile.d/*
    ~/.xprofile
    /etc/X11/xinit/xinitrc.d/*
    startxfce4

That brings up Xfce, and any environment variables set by this time will be valid for anything started from the Xfce session. Therefore I place an umask setting in .xprofile, so any program that creates files will use the correct umask smile

When I start a bash terminal, this is what happens:

/etc/profile
    /etc/profile.d/*
    /etc/bash.bashrc
~/.bash_profile
    ~/.bashrc
        ~/.bash_aliases

The reason ~/.bash_profile is run is that I have ticked the checkbox in Xfce Terminal to run the shell as a login shell. If I hadn't done that, then only ~/.bashrc would have been run - which is why I put my PATH in ~/.bashrc (along with umask again, to correct the setting from /etc/profile, which overrides my .xprofile umask) smile

I have cleaned up my stuff a little, so this can easily be more complex.
It's useful to read up on the configuration of Bash and Lightdm or whatever you're using, just to make sure that you understand what you do, whatever you do!

And if anybody wants to bash my bash-settings, please do - it's all about learning smile

Edit: Just tidying up a little

Last edited by Ferdinand (2023-07-24 08:41:41)

Offline

Board footer

Powered by FluxBB