Changing the $PATH variable globally

,

Hi! I recently switched from macOS to Fedora 40 and I’m trying to figure out a few things - one of which is changing the $PATH variable “globally” so all applications can see the changes.

On macOS, this could be done by simply adding a path to /etc/paths. I believe even Windows has a way to this. But on Linux, the only way I found is adding export PATH=... to my .zshrc file, which only makes the changes visible to apps that are launched through the terminal. Is there some other way on Fedora?

Let’s first check how “global” you want it to be: e.g., setting the PATH in a shell rc file changes the path for that shell and programmes started from there only. So, a user shell rc file does not (in general) determine what your desktop environment sees; a system shell rc file does not either, unless that DE is started from a shell script (which is why we used to do it that way).

man environment.d tells you how to set variables which are passed on to all system or user services/sessions (depending on where you put the setting). I’ve moved my user PATH setting to .config/environment.d/path-home.conf so that not only my shell sees that, but also my DE (sway) which is not started via a shell.

Globally in sense of all users on the system, you can follow this: https://www.baeldung.com/linux/path-variable#2-globally

You should strongly consider using the default paths:

/usr/local/bin
~/.local/bin
~/bin

This helps reduce potential issues, including those related to SELinux.

2 Likes