Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
[Solved] macOS - How to add a path to $PATH using /etc/paths.d
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2815
Topic starter
January 6, 2025 10:22 AM
Sometimes we want to add a path to the environment variable $PATH, so when typing a statement in Terminal, the command will be found.
As an example, I'm storing my custom executables in
~/.local/bin
So for an executable stored in this location to be found, we need to add that path to the environment variabel which can eb done in some of the usual ways seen in Linux and the likes.
One cool feature I found though (assuming your Mac is only being used by yourself of course) is by making a file holding that path in
/etc/paths.d
So for example create the file like so (you can call the filename anything you like):
sudo nano /etc/paths.d/my_local_executables
Enter the path
~/.local/bin
And press CTRL+X to save the file. You'll need to close Terminal completely, and after opening Terminal again, you'll see the path being part of the environment variable. You can look at the $PATH environment variable like so:
echo $PATH