Matlab on macOS doesn't source ~/.zshrc
On macOS, Matlab does not source ~/.zshrc. This issue has existed at least since macOS started using ZSH as the default shell.
To workaround this issue, particularly when programs from package managers like Homebrew are needed, add a setup script to the Matlab project containing like:
if ~ismac
return
end
% Add Homebrew to the PATH
[ret, homebrew_prefix] = system('brew --prefix');
if ret == 0
p = fullfile(strip(homebrew_prefix), "bin");
if isfolder(p)
setenv('PATH', append(p, pathsep, getenv('PATH')))
end
end
Then programs installed by Homebrew like CMake, GCC, etc. will be on Path environment variable in Matlab.
Note that the Matlab commands below do not help:
!source ~/.zshrc
system("source ~/.zshrc")