Matlab on macOS doesn't source shell config
On macOS, Matlab does not source any shell configuration files like ~/.zshrc
or ~/.bashrc
.
Any environment variables set in these files, such as those added by package managers like Homebrew, will not be available in the Matlab environment.
Instead, set desired environment variables in the Matlab startup.m script like:
edit(fullfile(userpath,'startup.m'))
Adding lines like
setenv("PATH", ['/opt/homebrew/bin/', pathsep, getenv("PATH")])
Where “/opt/homebrew/bin” was obtained from the system command brew --prefix
.
We recommend not running system() scripts in startup.m unless truly necessary to avoid delaying Matlab startup time or affecting startup stability.
Then programs installed by Homebrew like CMake, GCC, etc. will be on Path environment variable in Matlab.
Note that the Matlab commands below only affect commands withing that same command line:
!source ~/.zshrc && ls
system("source ~/.zshrc && ls")