Using MATLAB Three – Installing Matlab Runtime on Ubuntu

1. Download Matlab Runtime

Download the appropriate Matlab Runtime version from the official website (https://ww2.mathworks.cn/products/compiler/matlab-runtime.html). Currently, I am using the latest Matlab Runtime 2024a as an example.

2. Install Matlab Runtime

The official installation guide can be found at (https://ww2.mathworks.cn/help/compiler_sdk/ml_code/install-the-matlab-runtime.html).

Use an FTP tool to upload the MATLAB_Runtime_R2024a_Update_4_glnxa64.zip file to a folder on the server. The folder path I use is /usr/local/src/matlabruntime.

If you encounter permission issues during upload, you need to change the folder permissions:

sudo chmod 777 /usr/local/src/matlabruntime

After uploading, there will be a MATLAB_Runtime_R2024a_Update_4_glnxa64.zip file in the folder, which needs to be unzipped:

unzip MATLAB_Runtime_R2024a_Update_4_glnxa64.zip

2.1. Interactive Installation

After unzipping, refer to the official website for two installation methods. One is interactive installation, which requires Ubuntu to have a graphical interface for interaction. If there is no graphical interface, an error will occur. Execute the command:

sudo -H ./install

Note: Interactive installation is not possible without a graphical interface.

2.2. Non-Interactive Installation of MATLAB Runtime

It is recommended to use the non-interactive installation method. For the 2024a version, use the following command to install:

sudo ./install -agreeToLicense yes

For versions below 2022a, use the following command to install:

Using the default installation:

sudo ./install -mode silent -agreeToLicense yes

Installing to the specified /data/tomcat/MCR folder:

./install -mode silent -agreeToLicense yes -destinationFolder /data/tomcat/MCR

3. Configure Environment Variables

The official documentation for configuring environment variables can be found at (https://ww2.mathworks.cn/help/compiler_sdk/ml_code/mcr-path-settings-for-run-time-deployment.html).

The table below specifies the default MATLAB Runtime installation folder for R2024a:

Platform MATLAB Runtime Installation Folder
Windows C:\Program Files\MATLAB\MATLAB Runtime\R2024a
Linux /usr/local/MATLAB/MATLAB_Runtime/R2024a
macOS /Applications/MATLAB/MATLAB_Runtime/R2024a

3.1. Simple Configuration of Environment Variables

Knowing the default installation folder and the official installation steps, we need to execute the following command:

export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}\
/usr/local/MATLAB/MATLAB_Runtime/R2024a/runtime/glnxa64:\
/usr/local/MATLAB/MATLAB_Runtime/R2024a/bin/glnxa64:\
/usr/local/MATLAB/MATLAB_Runtime/R2024a/sys/os/glnxa64:\
/usr/local/MATLAB/MATLAB_Runtime/R2024a/extern/bin/glnxa64"

Check the environment variable:

echo $LD_LIBRARY_PATH

Check the GNU C library version:

ldd –version

If the displayed version is 2.17 or lower, use the following command to add to the environment variable:

export LD_PRELOAD="${LD_PRELOAD:+${LD_PRELOAD}:}\
<MATLAB_RUNTIME_INSTALL_DIR>/bin/glnxa64/glibc-2.17_shim.so"

The complete installation steps are shown below:

3.2. Persistent Configuration of Environment Variables

After configuring the environment variables, this method is not persistent. To make it persistent, you need to configure it in a configuration file.

Common configuration files include ~/.bashrc, ~/.bash_profile, and ~/.profile. Usually, editing the ~/.bashrc file is the most common practice, as it is automatically loaded whenever a new interactive shell session is started.

The following are the steps to configure the LD_LIBRARY_PATH environment variable as persistent:

Step 1: Edit the ~/.bashrc File

Open the ~/.bashrc file using a text editor. For example, you can use the nano editor:

nano ~/.bashrc

Step 2: Add Environment Variable Configuration

Add the following content to the end of the ~/.bashrc file:

export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}\
/usr/local/MATLAB/MATLAB_Runtime/R2024a/runtime/glnxa64:\
/usr/local/MATLAB/MATLAB_Runtime/R2024a/bin/glnxa64:\
/usr/local/MATLAB/MATLAB_Runtime/R2024a/sys/os/glnxa64:\
/usr/local/MATLAB/MATLAB_Runtime/R2024a/extern/bin/glnxa64"

Step 3: Save and Close the File

Save the file and exit the editor. If you are using nano, you can press Ctrl + O and then Enter to save the file, and then press Ctrl + X to exit the editor.

Step 4: Apply the Changes

To make the changes in the ~/.bashrc file take effect immediately, you can run the following command:

source ~/.bashrc

This way, the LD_LIBRARY_PATH environment variable will be permanently set. Each time you open a new terminal or shell session, the environment variable will be automatically loaded.

Verify Configuration

You can verify if the LD_LIBRARY_PATH environment variable is correctly configured using the following command:

echo $LD_LIBRARY_PATH

Ensure the output includes the MATLAB Runtime path you configured.

Using ~/.profile or ~/.bash_profile (Optional)

If you find that the ~/.bashrc file is not loaded in some cases, such as when logging into a graphical interface, you can try editing the ~/.profile or ~/.bash_profile file:

nano ~/.profile

or

nano ~/.bash_profile

Then add the environment variable configuration, save and close the file, and finally run source ~/.profile or source ~/.bash_profile to apply the changes.

By Tim

Leave a Reply

Your email address will not be published. Required fields are marked *