PATH variable always stay the same

Hi,

For whatever reason, it doesnt matter what files I make changes to, to export new PATH variable.

The $PATH variable always stays the same “/usr/local/bin:/usr/bin”.

Anything I can do about this?

Is there a hidden file holding these variables on?

Thanks.


I even did a ripgrep in attempt to find, but there are always at least three. And yet in the errors and by trying to access the $PATH directly, its only two paths in it.

/etc/login.defs:ENV_SUPATH	PATH=/usr/local/sbin:/usr/local/bin:/usr/bin
/etc/login.defs:ENV_PATH	PATH=/usr/local/sbin:/usr/local/bin:/usr/bin
/etc/ssh/sshd_config:# This sshd was compiled with PATH=/usr/local/sbin:/usr/local/bin:/usr/bin
/opt/postman/app/resources/app/node_modules/simple-swizzle/node_modules/is-arrayish/yarn-error.log:  /Users/junon/.yarn/bin:/Users/junon/.config/yarn/global/node_modules/.bin:/Users/junon/perl5/bin:/Users/junon/google-cloud-sdk/bin:/usr/local/sbin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/junon/bin:/Users/junon/.local/bin:/src/.go/bin:/src/llvm/llvm/build/bin:/Users/junon/Library/Android/sdk/platform-tools:/Users/junon/n/bin:/usr/local/texlive/2017/bin/x86_64-darwin/
/usr/lib/initcpio/init:export PATH='/usr/local/sbin:/usr/local/bin:/usr/bin'
/usr/lib/bash/Makefile.inc:CFLAGS = -march=x86-64-v3 -mtune=generic -O3 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=3 -Wno-error -fstack-clash-protection -fcf-protection -mpclmul -g -ffile-prefix-map=/tmp/pkg/src=/usr/src/debug/bash -flto=auto -DDEFAULT_PATH_VALUE='"/usr/local/sbin:/usr/local/bin:/usr/bin"' -DSTANDARD_UTILS_PATH='"/usr/bin"' -DSYS_BASHRC='"/etc/bash.bashrc"' -DSYS_BASH_LOGOUT='"/etc/bash.bash_logout"' -DNON_INTERACTIVE_LOGIN_SHELLS   -fprofile-partial-training -fprofile-use
/usr/lib/systemd/system-environment-generators/10-arch:echo 'PATH=/usr/local/sbin:/usr/local/bin:/usr/bin'
/usr/share/factory/etc/ssh/sshd_config:# This sshd was compiled with PATH=/usr/local/sbin:/usr/local/bin:/usr/bin
/usr/share/doc/fish/tutorial.html:<span class="go">/usr/local/sbin:/usr/local/bin:/usr/bin</span>
/usr/bin/update-smart-drivedb:export PATH="/usr/local/bin:/usr/bin:/bin"
/usr/share/fish/man/man1/fish-tutorial.1:/usr/local/sbin:/usr/local/bin:/usr/bin
/usr/share/fish/man/man1/fish-doc.1:/usr/local/sbin:/usr/local/bin:/usr/bin
/usr/bin/bashbug:CFLAGS="-march=x86-64-v3 -mtune=generic -O3 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=3 -Wno-error -fstack-clash-protection -fcf-protection -mpclmul -g -ffile-prefix-map=/tmp/pkg/src=/usr/src/debug/bash -flto=auto -DDEFAULT_PATH_VALUE='"/usr/local/sbin:/usr/local/bin:/usr/bin"' -DSTANDARD_UTILS_PATH='"/usr/bin"' -DSYS_BASHRC='"/etc/bash.bashrc"' -DSYS_BASH_LOGOUT='"/etc/bash.bash_logout"' -DNON_INTERACTIVE_LOGIN_SHELLS   -fprofile-partial-training -fprofile-use"
/usr/share/oh-my-zsh/plugins/chruby/chruby.plugin.zsh:  if PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" command ruby &>/dev/null; then
/usr/share/smartmontools/smartd_warning.sh:export PATH="/usr/local/bin:/usr/bin:/bin"

Dang this has been a beat since I’ve last done it but maybe something like

I needed to add it to my ~/.profile or ~/.bashrc file.


export PATH="$PATH:/path/to/dir

Depending on what you’re doing, you also may want to symlink to binaries:

cd /usr/bin
sudo ln -s /path/to/binary binary-name

Note that this will not automatically update your path for the remainder of the session. To do this, you should run:

source ~/.profile 
or
source ~/.bashrc

Hopefully that helps

I edited the post above.


Also an example.

I tried setting export PATH="$HOME/.cargo/bin:$PATH" in .bashrc, .profile, .bash_profile, and on /etc/profile use the append fn, but nothing updated the variable.


I tired logout/login and restart, didnt matter.


After source them into a shell, it loads the variable, but lets say I open a executable that depends on those.

It shows an error or doesnt even open and the error contains only the two paths mentioned above.

Which is why I wanted to see if anyone know what is the file used by the system.


Here is an example

Unable to spawn zellij because:
No viable candidates found in PATH "/usr/local/bin:/usr/bin"
⚠️  Process "zellij" in domain "local" didn't exit cleanly
Exited with code 1.
This message is shown because exit_behavior="CloseOnCleanExit"

Wezterm crash because it is unable to find ~/.cargo/bin folder. Alacritty doesnt even open, since I set nushell to be the default shell, and its located there also.

Error above is from zellij which is also located there, but even if I change to nu, same error.


If I change to bash, it works, no errors, probably because it’s located in one of the two paths.

Hence the problem with the global $PATH variable, in case other paths are needed.


I wonder if there is a global file setting and enforcing those two. Because it seems related to the system rather than a shell.

Ok, I found something that worked.

I checked /etc/environment and it was empty. By setting it there and restarting, it seems to have worked, now other PATHs from nushell also get loaded onto the $PATH variable.

What is weird is that on my other machine, a debian based OS, even though there is a PATH in /etc/environment, the one from cargo are not there, and it seems to work by only setting it to ~/.profile or ~/.bash_profile.

Maybe this is a bug on this OS? @naim

So does it work on the Debian-based OS or not? I think its likely that you need to provide an absolute path in /etc/profile with append_path rather than using the ~ short handle.

$PATH did not update when I tried before with the ~/ on append_path.

What is odd is that the append_path had 3 path setup, still $PATH was only showing two.

Regardless, on the debian based OS, I dont even have the append_path fn, nor any other pathing setup on /etc/profile.


Two obvious problems.

1- Retention of the 2 paths only.
2- The need of setting it outside $HOME based files.

Here is how it is on the debian based files from PopOS.

Only .profile has the cargo import and was enough. Of course .bash_profile are importing from it. I know it to be true as I triggered the same problem without having it set.

I installed as another on my desktop today, and now by default I got this.

echo $PATH
/usr/local/bin /usr/bin /usr/bin/site_perl /usr/bin/vendor_perl /usr/bin/core_perl

Why those perl paths? @naim

Only places I found them were

/etc/profile.d/perlbin.sh:[ -d /usr/bin/site_perl ] && append_path '/usr/bin/site_perl'
/etc/profile.d/perlbin.csh:[ -d /usr/bin/site_perl ] && setenv PATH ${PATH}:/usr/bin/site_perl
/usr/lib/perl5/5.40/core_perl/Config_heavy.pl:config_arg14='-Dsitescript=/usr/bin/site_perl'
/usr/lib/perl5/5.40/core_perl/Config_heavy.pl:config_args='-des -Dusethreads -Duseshrplib -Doptimize=-march=x86-64-v3 -mtune=haswell -O3 -pipe -fno-plt -fexceptions -mpclmul         -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security         -fstack-clash-protection -fcf-protection -g1 -ffile-prefix-map=/startdir/src=/usr/src/debug/perl -flto=auto -Dprefix=/usr -Dvendorprefix=/usr -Dprivlib=/usr/share/perl5/core_perl -Darchlib=/usr/lib/perl5/5.40/core_perl -Dsitelib=/usr/share/perl5/site_perl -Dsitearch=/usr/lib/perl5/5.40/site_perl -Dvendorlib=/usr/share/perl5/vendor_perl -Dvendorarch=/usr/lib/perl5/5.40/vendor_perl -Dscriptdir=/usr/bin/core_perl -Dsitescript=/usr/bin/site_perl -Dvendorscript=/usr/bin/vendor_perl -Dinc_version_list=none -Dman1ext=1perl -Dman3ext=3perl -Dlddlflags=-shared -Wl,-O1 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now          -Wl,-z,pack-relative-relocs -flto=auto -Dldflags=-Wl,-O1 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now          -Wl,-z,pack-relative-relocs -flto=auto -Dloclibpth=/usr/lib/db5.3 -Dlocincpth=/usr/include/db5.3'
/usr/lib/perl5/5.40/core_perl/Config_heavy.pl:installsitescript='/usr/bin/site_perl'
/usr/lib/perl5/5.40/core_perl/Config_heavy.pl:sitescript='/usr/bin/site_perl'
/usr/lib/perl5/5.40/core_perl/Config_heavy.pl:sitescriptexp='/usr/bin/site_perl'
/usr/share/fish/vendor_conf.d/perlbin.fish:    for perldir in /usr/bin/site_perl /usr/bin/vendor_perl /usr/bin/core_perl

Also there is no .profile generated, different from the other time.

drwxr-xr-x   - user 21 set 16:02  Videos
.rw-r--r--  21 user 21 set 16:00 󱆃 .bash_logout
.rw-r--r--  57 user 21 set 16:00 󱆃 .bash_profile
.rw-r--r-- 172 user 21 set 16:00 󱆃 .bashrc
.rw-r--r--  56 user 21 set 16:00 󱆃 .zshrc

Lastly, I found why on the behavior, that seems to mainly affect alacritty and wezterm.

That first time I did the setup, I set the default shell to nushell. Even though I speicific the full path on /etc/shells, still wasnt enough.

Now, after changing manually, and testing on alacritty, immediatelly it didnt open, like last time. While gnome terminal, were still on fish.

So far, only solution
sudo echo 'PATH="/usr/local/bin:/usr/bin/:~/.cargo/bin"' >> /etc/environment


I suppose if the system thinks fish is the main shell, rather than sh or bash, then that would be why whatever is set on .profile, .bash_profile or else, would have no effect.

That would be the “bug” created by your default OS setting. @naim

we are using fish as default shell, which is not POSIX compatible(also ~/.bash_profile works only when user shell is bash) and therefore the paths you are inserting the PATH changes into are “ignored”.

you need to append values to the PATH in such way:
set -p PATH ~/.cargo/bin in ~/.config/fish or ~/.fish_profile

That’s pretty much what the sum on the understanding came to.

Still, it should not be dependant on fish, as it was a system-wide need. So, in the end, /etc/environment were probably the right place to put it.