Install MATLAB on a remote server
Context
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
- 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
andnetwork.lic
- Copy those two files on the remote server using scp command.Copy the files preferably in the home directory.
- SSH into the server.
- 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.
wget http://swrepo.iitkgp.ac.in/Matlab2021B/Linux/R2021b_Linux.iso
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
destinationFolder=/home/ubuntu/matlab
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
fileInstallationKey=12345-24564-.....
agreeToLicense=yes
Log files to check if installation is successful or not
outputFile=/tmp/mathworks_ubuntu.log
Path to network.lic
file, which was copied on to the server using scp in the second step
licensePath=/home/ubuntu/network.lic
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
- 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.
- In case of permission issues, try running the same command using
sudo
Usage
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.
- Move to the directory where your code is present
- Open a new tmux session, using the command
tmux new
- Open MATLAB without desktop using the command -
matlab -nodesktop
- You get access to MATLAB's command window
- Run the script you wish to run
- Save the workspace variables in a .mat file by runnning the following command in MATLAB command window -
save('script_vars.mat')
scp
the.mat
file to your machine- Load the
.mat
file on MATLAB, installed on your personal machine using -load('script_vars.mat')
- You can now write code to analyse the data in
.mat
file
Contact
If you face any issues while following the above instructions, feel free to contact Raghavendra Kaushik(raghavendra.kaushik.iitkgp@gmail.com)