Matlab: Difference between revisions

From NixOS Wiki
imported>Mazurel
Created page with "MATLAB (an abbreviation of "matrix laboratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks.[https://en.wikip..."
 
Zimward (talk | contribs)
m fix typo: runned -> run
 
(5 intermediate revisions by 3 users not shown)
Line 5: Line 5:
Matlab due to it's installation method and licensing is really problematic to package into nixpkgs[https://github.com/NixOS/nixpkgs/issues/56887], that is why the only way to install it is to use some imperative way (to install it outside the nix store).
Matlab due to it's installation method and licensing is really problematic to package into nixpkgs[https://github.com/NixOS/nixpkgs/issues/56887], that is why the only way to install it is to use some imperative way (to install it outside the nix store).


== Imperative installation without flakes ==
=== (Recommended) Based on Doronbehar [https://gitlab.com/doronbehar/nix-matlab] repo (with or without flakes)===


These instructions are based on '''tviti'''[https://github.com/tviti/nix-cfg/tree/aunuu/pkgs/matlab] GitHub repository. It is also worth to look at '''doronbehar'''[https://gitlab.com/doronbehar/nix-matlab] GitLab repository which is based on '''nix flakes'''[https://nixos.wiki/wiki/Flakes].
You may prefer to use [https://gitlab.com/doronbehar/nix-matlab this method] by doronbehar. It is based on the one described below, but requires less work.
 
 
=== Based on tviiti[https://github.com/tviti/nix-cfg/tree/aunuu/pkgs/matlab] repo or custom work (without flakes) ===


Firstly you need to download zipped Matlab archive for Linux from the official webpage. Then create a folder for the installation files and unzip the archive into that folder via <code>unzip -X -K</code> command.
Firstly you need to download zipped Matlab archive for Linux from the official webpage. Then create a folder for the installation files and unzip the archive into that folder via <code>unzip -X -K</code> command.


Then you will need <code>shell.nix</code> file that will create proper environment. This shell should use <code>buildFHSUserEnv</code> function and should contain all the relevant packages. Personally I have used tviti[https://github.com/tviti/nix-cfg/tree/aunuu/pkgs/matlab] imperative Matlab shell.  
Then you will need <code>shell.nix</code> file that will create proper FHS environment. This shell should use <code>buildFHSUserEnv</code> function and should contain all the relevant packages. Personally I have used tviti[https://github.com/tviti/nix-cfg/tree/aunuu/pkgs/matlab] imperative Matlab shell.  


{{Tip|In case you also want to use tviti work, clone his repo and get into pkgs/matlab. Then run <code>nix-shell</code> and <code>matlab-shell</code> to get into installation environment. More info can be found in his repo[https://github.com/tviti/nix-cfg/tree/aunuu/pkgs/matlab]}}
{{Tip|In case you also want to use tviti work, clone his repo and get into pkgs/matlab. Then run <code>nix-shell</code> and <code>matlab-shell</code> to get into installation environment. More info can be found in his repo[https://github.com/tviti/nix-cfg/tree/aunuu/pkgs/matlab]}}
Line 18: Line 21:


After successful installation, you should add Matlab do your <code>configuration.nix</code> file. Personally I have used modified tvitii[https://github.com/tviti/nix-cfg/tree/aunuu/pkgs/matlab] files. I have simply switched <code>runPath</code> to the path of freshly installed Matlab folder. Then in my configuration.nix I have used his matlab folder like so:
After successful installation, you should add Matlab do your <code>configuration.nix</code> file. Personally I have used modified tvitii[https://github.com/tviti/nix-cfg/tree/aunuu/pkgs/matlab] files. I have simply switched <code>runPath</code> to the path of freshly installed Matlab folder. Then in my configuration.nix I have used his matlab folder like so:
<pre>
<syntaxHighlight lang=nix>
...
...
let
let
Line 27: Line 30:
     environment.systemPackages = [ ... tviti-matlab.matlab  ... ];
     environment.systemPackages = [ ... tviti-matlab.matlab  ... ];
...
...
</pre>
</syntaxHighlight>


{{Evaluate}}
{{Evaluate}}
Line 33: Line 36:
Now you should have <code>matlab</code> in your path and be able to run it via <code>matlab</code> command.
Now you should have <code>matlab</code> in your path and be able to run it via <code>matlab</code> command.


== Weird java errors ==
==== Weird java errors ====


In case you have java errors, and you are using tvitii[https://github.com/tviti/nix-cfg/tree/master/pkgs/matlab]  derivation, you may need to modify <code>matlab.nix</code> to something like this:
In case you have java errors, and you are using tvitii[https://github.com/tviti/nix-cfg/tree/master/pkgs/matlab]  derivation, you may need to modify <code>matlab.nix</code> to something like this:
<pre>
<syntaxHighlight lang=nix>
{ common,  buildFHSUserEnv }:
{ common,  buildFHSUserEnv }:
buildFHSUserEnv {
buildFHSUserEnv {
Line 45: Line 48:
   runScript = "${common.runPath}/bin/matlab";
   runScript = "${common.runPath}/bin/matlab";
}
}
</pre>
</syntaxHighlight>
 
=== Other possible issues ===
 
==== I can't see anything ====
 
If you are using Window Manager and Matlab does not display anything, you will need to use <code>wmname</code> command (preferably when starting your session). Just run <code>wmname LG3D</code>, run Matlab again and the issue should be fixed.
 
==== No hardware support ====
 
There is a great answer about that here on Matlab answers[https://www.mathworks.com/matlabcentral/answers/241850-matlab-failing-to-find-hardware-opengl#answer_263092].


== Imperative installation with flakes ==
Summarizing this answer:
<syntaxHighlight lang=bash>
cd <your_matlab_location>/sys/os/glnxa64/
sudo mv libstdc++.so.6 libstdc++.so.6.bak
sudo ln -s /usr/lib64/libstdc++.so.6  libstdc++.so.6
</syntaxHighlight>


These instructions are based on '''doronbehar'''[https://gitlab.com/doronbehar/nix-matlab] GitLab repository.
You will not have <code>/usr/lib64/libstdc++.so.6</code> at the time of following the steps, but Matlab will be run in FHS env, and this path will be visible for it.


{{Expansion|Flakes approach should be documented}}
[[Category:Applications]]

Latest revision as of 09:24, 12 May 2024

MATLAB (an abbreviation of "matrix laboratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks.[1]

Installation

Matlab due to it's installation method and licensing is really problematic to package into nixpkgs[2], that is why the only way to install it is to use some imperative way (to install it outside the nix store).

(Recommended) Based on Doronbehar [3] repo (with or without flakes)

You may prefer to use this method by doronbehar. It is based on the one described below, but requires less work.


Based on tviiti[4] repo or custom work (without flakes)

Firstly you need to download zipped Matlab archive for Linux from the official webpage. Then create a folder for the installation files and unzip the archive into that folder via unzip -X -K command.

Then you will need shell.nix file that will create proper FHS environment. This shell should use buildFHSUserEnv function and should contain all the relevant packages. Personally I have used tviti[5] imperative Matlab shell.

Get into the proper environment via nix-shell. Then you can safely start Matlab installer by running ./install script in the Matlab installation folder. It is strongly preferred to install Matlab somewhere in the user home folder.

After successful installation, you should add Matlab do your configuration.nix file. Personally I have used modified tvitii[7] files. I have simply switched runPath to the path of freshly installed Matlab folder. Then in my configuration.nix I have used his matlab folder like so:

...
let
    tviti-matlab = pkgs.callPackage ./matlab { };
...
in {
...
    environment.systemPackages = [ ... tviti-matlab.matlab  ... ];
...

Now you should have matlab in your path and be able to run it via matlab command.

Weird java errors

In case you have java errors, and you are using tvitii[8] derivation, you may need to modify matlab.nix to something like this:

{ common,  buildFHSUserEnv }:
buildFHSUserEnv {
  name = "matlab";

  targetPkgs = pkgs: with pkgs; common.targetPkgs pkgs;

  runScript = "${common.runPath}/bin/matlab";
}

Other possible issues

I can't see anything

If you are using Window Manager and Matlab does not display anything, you will need to use wmname command (preferably when starting your session). Just run wmname LG3D, run Matlab again and the issue should be fixed.

No hardware support

There is a great answer about that here on Matlab answers[9].

Summarizing this answer:

cd <your_matlab_location>/sys/os/glnxa64/
sudo mv libstdc++.so.6 libstdc++.so.6.bak
sudo ln -s /usr/lib64/libstdc++.so.6  libstdc++.so.6

You will not have /usr/lib64/libstdc++.so.6 at the time of following the steps, but Matlab will be run in FHS env, and this path will be visible for it.