Sublime Forum

Why does Sublime use bash and NOT zsh on macOS?

#1

Not realizing that the build command (⌘b) in ST4 uses bash by default on macOS caused me a big headache recently. It took me days to figure out that the reason I wasn’t able to get my one Python script to run (I kept getting ModuleNotFoundError) was because sublime by default uses the bash shell and NOT zsh. zsh is the default on macOS and has been for years now. Since ST4 wasn’t seeing the same python3 executable on the PATH (or the same PATH for that matter) my script wasn’t running properly. If I ran it in terminal it worked fine without any errors.

After reading more about the build systems I came across this one line in regards to the shell_cmd string: “A shell command [executes using] bash on Mac and Linux” sublime docs - build system.

I found a few different ways to fix this:

  1. Modifying .bash_profile to match the exports, assignments, and PATH setup that I have in .zprofile and .zshrc.
  2. Changing the default build system configuration for python (Python.sublime-build):
"shell_cmd": "python3 -u \"$file\""
// to this
"shell_cmd": "/full_path_to_python/python -u \"$file\""
  1. Overriding the default exec.py file (making a new file in Packages/Default/exec.py) and changing:
elif sys.platform == "darwin":
    # Use a login shell on OSX, otherwise the users expected env
    # vars won't be setup
    cmd = ["/usr/bin/env", "bash", "-l", "-c", shell_cmd]
# to 
    cmd = ["/usr/bin/env", "zsh", "-l", "-c", shell_cmd]

While changing my .bash_profile is probably the easiest thing, sublime should be using zsh to align with the default on macOS. It would also be nice if this was a user configurable setting that wasn’t hidden in some obscure exec.py file in the compressed Default directory.

0 Likes

Build Systems not correctly searching PATH on macOS
#2

Well the obvious answer to the question in the title is that in 2019 when macOS changed the default to zsh, there were already countless customers who had an existing working ST setup and SublimeHQ probably didn’t want to disrupt them.

Now that that’s becoming more and more ancient history, maybe the balance of what is disruptive has tipped the other way.

0 Likes

#3

Sublime Text uses bash for build systems because it is a posix-compliant shell, unlike zsh. This is most often the desired behavior because it makes build systems work for both Linux and macOS.

Sublime Text also gets your environment variables from your default shell (presumably zsh) when starting. These environment variables get inherited and passed to build systems. It’s possible you’ve misconfigured your environment variables: They should be getting set in .zshenv or .zprofile for them to be picked up by a login shell. It’s also possible this failed due to a timeout; an error should be logged in the console (View > Show Console) in that case.

1 Like