Skip to main content

Install MATLAB-Engine for Julia on Apple Silicon M-series chip

· 2 min read

Install the new MATLAB Engine with MATLAB R2023b

MATLAB has released the new native version of MATLAB R2023b, which can smoothly work on Apple Silicon. You can download from the below link:

bookmark

Note: Remember to select the apply silicon version.

The MATLAB.jl has also updated, you can add the package from Julia by using Pkg; Pkg.add(”MATLAB”). Once the installation and precompile finished, you can use the MATLAB engine in Julia.

Issue with MATLAB Engine on Apple Silicon

Because MATLAB are still running on x86_64 platform, MATLAB Engine for Python or Julia is invalid on Apple Silicon native platform. If you want to use MATLAB Engine, you can only install all the software on x86_64 platform.

Install Homebrew via x86_64 platform

The solution can be found from stackoverflow discuss.

  1. Install homebrew via arch-x86_64 platform
arch --x86_64 /bin/shell -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Add arch-x86_64 to PATH in ~/.zshrc. by open ~/.zshrc and add the following line to the end of the file.
alias brow='arch --x86_64 /usr/local/Homebrew/bin/brew'
alias ib='PATH=/usr/local/bin'

The brow is the alias for brew and ib is the alias for arch-x86_64.

  1. Add an alias to switch between arch-x86_64 and arch-arm64 platform
alias a86='env arch -x86_64 zsh'
alias a64='env arch -arm64 zsh'

Install Julia via x86_64 platform

  1. Install Julia via arch-x86_64 platform homebrew.
brow install julia

Wait for the installation.

Install MATLAB Engine for Julia

  1. Start Julia ib julia and install MATLAB package.
import Pkg; Pkg.add("MATLAB")
  1. Test the availability.
using MATLAB
a = mxarray(Float64,5)
nrows(a)

The return value should be 5.

Everytime when you run Julia rememeber to add ib julia rather than julia to start Julia if you want to use MATLAB Engine.

If you only need the Julia function, I suggest to run native version of Julia on Apple Silicon.