How to execute matlab from terminal in Ubuntu (Linux)?

Dr. Muniba Faiza
2 Min Read

While trying to install Matlab [1], it generally gives an error stating “matlab: command not found.”. Here, we provide a solution to this error.

This error occurs when the Matlab is not in your path. This could be because during installation it was unable to write to the default location, i.e., /usr/local/ and you have installed the Matlab in some other location. Or you have installed Matlab successfully but not added to the path. Let’s go through the solutions for both situations.

1. Running installer with sudo permission

When you run the installer without the sudo permissions (./install), it will not install Matlab in the default location stating “cannot create a folder in /usr/local” or “cannot write to /usr/local/“. You need to provide permissions using the sudo command. But when you try to run the installer with the sudo command then it keeps running without displaying anything.

So, to run the installer with the sudo command, you will first have to allow the root user to access the running X server. Open a terminal (Ctrl+Alt+T) and paste the following command.

$ xhost +SI:localuser:root

Now, you can run the installer with the sudo command as shown below.

$ sudo ./installer

2. Adding to the path

Open the bashrc file.

$ sudo nano ~/.bashrc

Add the following command at the end of the file.

$ export PATH=$PATH:/usr/local/MATLAB/R2022a/bin

Here, R2022a is the Matlab version. Replace it with your installed version.

Save and close the file.

$ source ~/.bashrc

Now, you can type $ matlab in the terminal to run the Matlab.


References

  1. MATLAB. (2022). version 9.12.0 (R2022a). Natick, Massachusetts: The MathWorks Inc.
Share This Article
Dr. Muniba is a Bioinformatician based in New Delhi, India. She has completed her PhD in Bioinformatics from South China University of Technology, Guangzhou, China. She has cutting edge knowledge of bioinformatics tools, algorithms, and drug designing. When she is not reading she is found enjoying with the family. Know more about Muniba
Leave a Comment

Leave a Reply