Emacs-plus PATH in macOS Sequoia
Important: this is for emacs-plus for macOS via Homebrew.
After the upgrade to macOS Sequoia, Emacs' Dired didn’t find gls, which made it impossible to navigate to folders and open files this way. When a program can’t find another program, it’s usually a sign something is wrong with the path environment.
On Mastodon, Jumile directed me toward a discussion about a similar error on Github. Seems to be a path issue indeed, from what I can tell. Something with PATH injection in Emacs (I don’t know what this is yet, but from the name, I get a vague idea. This seems to be an interesting read)
Two solutions and a workaround.
The workaround is to launch Emacs from the terminal, which loads the environment correctly.
Something more permanent is manually doing what emacs-plus does automatically: copy and apply the PATH in the init file, as explained in the GitHub above. To do that, you want to go into Info.plist
inside the Emacs package: /opt/homebrew/Cellar/emacs-plus@[your version number here]/[version number]/Emacs.app/Contents
and locate the PATH string (search for “PATH”). On my system, it looks like this:
<string>/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin</string>
And copy it into the init file, telling it to set the environment like so:
(setenv "PATH" "/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin")
(setq exec-path (split-string (getenv "PATH") path-separator))
Something even better came from David Hagerty: exec-path-from-shell. This package is “copying important environment variables from the user’s shell: it works by asking your shell to print out the variables of interest, then copying them into the Emacs environment.”
I tested it out, and it works as advertised. This is a more reliable solution than copying the path manually each time, though it’s important to understand what’s going on and what it does.
On Reddit, slashkehrin added the actual path issue on Github.