MATLAB: License Manager Error -9 when run as administrator but not normally

access deniederror -9licenselinuxpermissionUbuntu

I have Ubuntu 16.04 and have a student version of Matlab and want to install a trial version of the Statistics and Machine Learning Toolbox. But the installer doesn't have permission (Access Denied: Unable to write to /usr/local/MATLAB/R2016b. Please select a different folder).
So I try to run Matlab with root permission using
sudo matlab &
but I get
License checkout failed.
License Manager Error -9
Your username does not match the username in the license file.
To run MATLAB on this computer, you must run the Activation client to reactivate your license.
Troubleshoot this issue by visiting:
http://www.mathworks.com/support/lme/R2016b/9
Diagnostic Information:
Feature: MATLAB
License path: /home/pjhellemn/.matlab/R2016b_licenses:/usr/local/MATLAB/R2016b/licenses/license.dat:/usr/local/MAT
LAB/R2016b/licenses/license_pjhellemn-Lenovo-ideapad-Y700-14ISK_3284817_R2016b.lic
Licensing error: -9,57.
How do I allow Matlab to be run with root permissions, so that I can install the toolbox?

Best Answer

Correct. When you sudo, your username becomes root, which is not what is in the license file.
To install toolboxes on Linux you should run the installer, which you would do while sudo'd
(OS-X has the same issue about sudo and username, but when you use the Add-on explorer or the installer on OS-X, the process will ask you to authenticate and then will proceed to allow you to install.)