How I Used MATLAB On Fedora Linux

Some time ago, I needed to use MATLAB on my Linux desktop to contribute to a project at school. There are a lot of ways to get MATLAB running on Linux, but the setup decribed below worked best for me.

I use Distrobox, a tool for running Linux distros in containers that integrate tightly with the host system. I was preparing to install MATLAB on my main container with the rest of my development tools when I found that the work had been done for me.

MathWorks, the company behind MATLAB, distributes a Docker container with MATLAB preinstalled on an Ubuntu base. I used this Ubuntu+MATLAB image to create a seperate container with Distrobox.

This setup worked fine, but the MATLAB GUI irked me. Some digging around led me to another great hit from MathWorks, an official MATLAB VSCode extension. The extension let me edit, run, and debug my code. I installed VSCode on my container and used Distrobox’s export feature so that I could see this instance of VSCode in my app launcher. VSCode is my editor of choice, so I was happy with my setup. Thankfully, I haven’t needed to use MATLAB and simply deleted the distrobox. Below are the actual steps I took on my Fedora Linux system.

  1. Install Distrobox.

    sudo dnf install distrobox
    
  2. Spin up distrobox with the Ubuntu+MATLAB image, and specify a custom HOME disrectory to keep generated program files out of my host’s HOME. See distrobox-create.

    distrobox-create --image docker.io/mathworks/matlab:latest --home [YOUR_DIRECTORY]
    

Note: After this step, you’re all set unless you want VSCode. You can enter the container and run matlab or create a .desktop file that executes the same command and export it.

  1. Install VSCode. See their instructions for Fedora.

  2. Install the MATLAB extension. From VSCode, punch in Ctrl+P and enter https://code.visualstudio.com/docs/setup/linux?originUrl=%2Fdocs#_rhel-fedora-and-centos-based-distributions.

  3. Lastly, export VSCode to see it in your app launcher. From inside your container run:

distrobox-export -a code

Because this setup relies on Distrobox, it should work on any compatible host OS.

Tags: