Page 1 of 1

how to alter $PATH system-wide on MX

Posted: Fri Apr 18, 2025 8:59 am
by zinger
I have a fair amount of scripts I've written over the years as well as some compiled programs that I want to be accessible to everyone on the system. I used to put them in /usr/local/bin, but MX uses that dir now so I made another bin under /usr/local/. I modified /etc/profile to add my new bin dir & thought that would suffice. NOPE. Worked fine for console logins, but for managed sessions (XFCE, Enlightenment. etc.) the $PATH was clobbered; back to some default value, I suspect by XDG_SOMETHING_OR_OTHER. I noticed that /etc/profile sources /etc/bash.bashrc (which exists on MX systems) so out of desperation, I copied & modified the PATH definitions there. Wonder of wondes, it worked! Both for console logins & managed sessions. Somewhere between /etc/profile & /etc/bash.bashrc you $PATH gets mutilated. I can't tell you how, by what, or WHY. If you know, please share.

TLDR:
To alter $PATH system-wide on MX, copy the PATH definitions from /etc/profile to /etc/bash.bashrc & make your modifications there. Make sure to put them AFTER the interactive check ([ -z "$PS1" ] && return). Of course, this is bash specific. zsh & other shell users, YMMV.

Re: how to alter $PATH system-wide on MX

Posted: Fri Apr 18, 2025 10:12 am
by thomasl
As you say, this does work but it's bash specific. And even worse, it doesn't work for apps that are started not from within a bash terminal (or generally via a bash shell). I used various more or less reliable workarounds over the years until I found that editing /etc/environment did the job (and I now use/edit that file for all systemwide environment variables). I think (but am not sure) this already worked for MX21. It certainly works for MX23. But as ever YMMV.

Re: how to alter $PATH system-wide on MX

Posted: Fri Apr 18, 2025 1:19 pm
by zinger
That is a valid point, thomasl.

I've also discovered /etc/bash.bashrc PATHs override /etc/skel/.profile which adds ~/bin if it exists, so you need to be sure to put ${HOME}/bin: in /etc/bash.bashrc if you use that method.

One advantage of using /etc/bash.bashrc over /etc/environment is you can use different PATHs for root & non-root users. I want my bin at the start of non-root users but at the end of root's PATH. Don't think you can do that in /etc/environment, although you could easily set root's path absolutely in its resource files.

The /etc/bash.bashrc method suites me fine since my bin is ~98% perl/bash scripts, but I'm going to experiment & see which I like better. I'd still like to know what buggers the path set in /etc/profile though.