2

I added another file to /etc/paths.d containing the file I want to add the path environment variable on macOS Sequoia. The file is saved. I need my Mac to pay attention, to update the PATH with the new item.

👉🏽 How do I get my Mac to update the path now?

I assume a restart of macOS will establish a newly updated path. But that seems extreme. How can I prompt an update of $PATH without bothering to restart the computer?

2
  • 1
    It should have an effect the next time you start a shell. Just open a new Terminal window. Commented May 2 at 20:49
  • There's probably no easy way to force existing shell sessions to take account of the change.  (After all, the system has no way to know whether you've changed your path, e.g. in a shell startup file, and you wouldn't want those changes to be overwritten.)  You can of course add a new path manually by executing e.g. export PATH="$PATH:/my/new/path".  Or you can use path_helper as per this answer. Commented May 3 at 13:00

2 Answers 2

1

Use your shell's builtin exec command to replace your current shell with a new interactive login shell. For the Bourne Again Shell:

First minimize your PATH variable, which will prevent path_helper from mangling your expected results.

PATH=/usr/bin:/bin:/usr/sbin:/sbin

then

exec bash -l

8
  • I doubt most people are using bash nowadays. That would be a deliberate choice. Commented May 3 at 15:23
  • @Marc Wilson- the solution works with all the korn/bourne like shells. :-) Commented May 3 at 15:34
  • @MarcWilson It requires a deliberate choice to migrate existing accounts from bash to zsh, so a lot of people will still use bash. Commented May 3 at 19:05
  • @fd0 It doesn't. If you say, maybe, exec $SHELL -l, it might. Depending on how you are invoking your currently running shell. More than a few people don't or won't use chsh and just mangle the launch config in Terminal.app. Commented May 3 at 20:28
  • @nohillside That's entirely true, but I wonder how many of those there still are. I haven't run into one myself in quite a while. Commented May 3 at 20:37
0

Running

PATH=$(cat /etc/paths.d/NEWFILE):$PATH 

will add the new path element directly into the current session.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.