Install MATLAB on a remote server

From Metakgp Wiki
Jump to navigation Jump to search

Context[edit | edit source]

If you have a piece of MATLAB code that requires high compute power, it is recommended that you take a remote server from the Meghamala Service: IIT Kharagpur and run your MATLAB code on the remote server. The following are the steps to install MATLAB on a remote server in KGP

Steps[edit | edit source]

  1. Getting License: Since MATLAB is a proprietary software, installing it requires a license. You need to mail [[1]] asking for the MATLAB license. You will receive 2 files named - FIK.txt and network.lic
  2. Copy those two files on the remote server using scp command.Copy the files preferably in the home directory.
  3. SSH into the server.
  4. Download the Linux ISO image of MATLAB on the server using wget command. For example if you want to install MATLAB 2021B version, run the following command on the server.

5. Mount the ISO image on a directory(make sure that directory has enough space, at least 50 GB) using the following command. Here we are mounting in a new directory called mathworks created in the the directory /media

sudo mount -o loop R2021b_Linux.iso /media/mathworks

6. In the /media/matworks directory, you will find many files. Among them, you will find the file called installer_input.txt

7. Copy the contents of the file - installer_input.txt and paste them in a new file with preferably same name in a different directory(for example in home). This installer_input.txt contains the MATLAB installation options, which need to be edited. The file is copied to a different location(like here home) and edited there because one can't edit the installer_input.txt file in the mounted location - /media/mathworks

8. Open the installer_input.txt present in home directory and edit the following lines

You can edit the options according to your usage. Here we assume that the machine username is ubuntu. Create a directory named matlab in home directory. We will be installing matlab in this directory. Hence path to this directory is the destinationFolder


Copy the text in the FIK.txt file,(file copied on the server in the second step) which is the format of xxxxx-xxxxx... and paste the key


Log files to check if installation is successful or not


Path to network.lic file, which was copied on to the server using scp in the second step


9. Now to install matlab as per the above options, move to the directory /media/mathworks , where MATLAB iso image was mounted. To install run the following command

sudo ./install -inputFile /home/ubuntu/installer_input.txt

The process will take some time. You can check the status of download at the file - /tmp/mathworks_ubuntu.log

(Mar 16, 2022 18:16:44) Exiting with status 0
(Mar 16, 2022 18:16:44) End - Successful

10. To run matlab as a executable, add an alias in the ~/.bashrc file

alias mat=/home/ubuntu/matlab/matlab/bin/matlab

Reload the session using the command - source ~/.bashrc

11. To check if matlab is installed or not, try running the command matlab -help

Troubleshooting[edit | edit source]

  1. Sometimes the installation process fails because the directory might not have enough space. Please recheck the issue. From time to time monitor the log file.
  2. In case of permission issues, try running the same command using sudo

Usage[edit | edit source]

To run a MATLAB code on a long time, it would be a good idea to run the script in the background using a tool called tmux.

Follow the steps.

  1. Move to the directory where your code is present
  2. Open a new tmux session, using the command tmux new
  3. Open MATLAB without desktop using the command - matlab -nodesktop
  4. You get access to MATLAB's command window
  5. Run the script you wish to run
  6. Save the workspace variables in a .mat file by runnning the following command in MATLAB command window - save('script_vars.mat')
  7. scp the .mat file to your machine
  8. Load the .mat file on MATLAB, installed on your personal machine using - load('script_vars.mat')
  9. You can now write code to analyse the data in .mat file

Contact[edit | edit source]

If you face any issues while following the above instructions, feel free to contact Raghavendra Kaushik([email protected])