CastorisCausa

Personal blog and hacks by Raymundo Cassani

I use Arch (BTW), so my OS has up-to-date software and packages. Unfortunately, this also means that Matlab (which is not officially supported in Arch Linux) can be a real headache to install and run, especially older versions as they relied in "older" libraries.

In the last years, I tried debugging and fiddling endlessly with libraries and dependencies to get Matlab to work. Many times with help of the ArchForums, this activity quickly became a huge time sink as often I needed different fixes for different Matlab versions. To be honest, I even considered switching permanently to Ubuntu just to avoid these headaches.

However, that migration will not be needed 😌, as recently Distrobox crossed my path and it completely changed the game.

In a nutshell, Distrobox creates a containerized environment based on an Ubuntu release that Matlab officially supports. Then, Matlab runs inside that container as if it were the native Ubuntu, but I still have seamless access to my home directory (and other files) because the container shares those with the host. On top of that, NVIDIA GPU support works out of the box with minimal fuss, so Matlab GPU-accelerated features run smoothly without complicated setup.

Distrobox: Ubuntu 22.04 with Matlab 2022b


A. In the host

  1. Install distrobox and podman (preferred, though Docker could be used):

    1
    $ sudo pacman -S distrobox podman
    
  2. Create the Ubuntu container with NVIDIA support (if needed):

    1
    $ distrobox create --image ubuntu:22.04 --name ubuntu-2204-nvidia --nvidia
    
  3. Enter the container:

    1
    $ distrbox enter ubuntu-2204-nvidia
    

B. In the container

  1. Install additional Ubuntu packages that Matlab 2022b needs:

    1
    $ sudo apt-get install libnss3 libatk-bridge2.0-0 libasound2 libxt6 libxft2 libsndfile1
    

    the list of required Ubuntu packages may grow depending on the Matlab features that are required.
    I'll keep updating this list as I encounter missing packages.

  2. Download the Matlab installer, unzip it and run the install script.
    Use the default installation path: /usr/local/MATLAB/R2022b

    1
    $ sudo ./install
    
  3. Create a symbolic link (so the binary has a different name from matlab):

    1
    $ sudo ln -s /usr/local/MATLAB/R2022b/bin/matlab /usr/local/bin/matlab22b
    
  4. Once Matlab is installed in the Ubuntu container, it be exported to the host for easy execution:

    1
    $ distrobox-export --bin /usr/local/bin/matlab22b --export-path ~/.local/bin
    

C. On the host again

  1. Just run

    1
    $ matlab22b
    

    the Ubuntu container will be started and matlab22b will be executed on it.

Conclusion

Distrobox for running Matlab versions on Arch is a simple and clean solution that avoids dependency issues and host system changes.

Comments

comments powered by Disqus