I would like to run mathematica scripts on a remote cluster in order to produce some plots. This cluster does not have X11 installed (the job is submitted to a queuing system).


I have a script file which, say contains

 Print["starting"]; pl= Plot[x,{x,0,1}]; Export["test.eps",pl]; 

in a test.m file;

But the line command

 math -script test.m

seems to require a display.

A few versions of mathematica ago (<7?) it would work with the option

  pl= Plot[x,{x,0,1},DisplayFunction->Identity]; 

cf this page. But this trick does not seem to work anymore, as mathematica seems to require a front-end to do the plot, even if it is not displayed in practice.


With Mathematica 10.0 or 11.0 how does one produce plots without display?


The issue is not with finding the Mathematica Kernel. The script runs fine until the lack of display is a problem.

Can't open display "localhost:14.0"
  • $\begingroup$ FWIW this works for me with DISPLAY unset, so it is not directly using the X server. Can you put Print[AbsoluteOptions@pl] in there to see if the issue is with Plot or with Export $\endgroup$
    – george2079
    Commented Jan 30, 2017 at 20:47
  • $\begingroup$ DISPLAY is the linux shell variable that has the X server address. Looking at your error I think the problem is you have DISPLAY set to localhost:14.0 when it should not be set at all if there is no server available. (I can reproduce your error if I set DISPLAY to something invalid) $\endgroup$
    – george2079
    Commented Jan 30, 2017 at 21:04
  • $\begingroup$ try unsetenv DISPLAY .. It needs to be removed, not just empty. It seems to be Export that is causing the problem by the way. $\endgroup$
    – george2079
    Commented Jan 30, 2017 at 21:12
  • 1
    $\begingroup$ Ah, i see. math falls back to a default display :0.0 in the event you have no DISPLAY variable set. That is not normal behavior, but at least explains why my fix doesn't work. $\endgroup$
    – george2079
    Commented Jan 30, 2017 at 22:20
  • 1
    $\begingroup$ It seems that M11.3 no longer requires xvfb, but M11.2 does. $\endgroup$
    – Szabolcs
    Commented Jan 28, 2019 at 13:23

2 Answers 2


Update: Starting with Mathematica 11.3, it is no longer necessary to have a running X server. Everything works out of the box.

Some operations require the front end, the most notable example being graphics rendering. On Linux, the front end requires an X server. Note that this does not mean that it requires a connected display.

If you are running interactively in an ssh session, the easiest way to provide an X server is to forward it from your own machine using ssh -X or ssh -Y.

If you are running it non-interactively, as it is usually the case on a cluster, then the typical solution is to install and use Xvfb. This is an X server that does not require a display. I have installed this in the past privately for my user, without root access.

If you are running on a HPC cluster, often the most practical solution is to just not export any graphics. Often (but not always) it is more practical to only export data on the cluster, and visualize it on your own machine, separately.


Indeed, after installing Xvfb, the following works

xvfb-run MathematicaScript -script test.m

Though interestingly not with Export for mathematica 10.3 (but ok with 11.0 or 9.0).

  • 1
    $\begingroup$ Thanks. It's a pity Wolfram broke this with recent version of Mathematica. $\endgroup$
    – chris
    Commented Jan 31, 2017 at 9:38
  • $\begingroup$ @chris It is not recent. It has been this way since version 6. $\endgroup$
    – Szabolcs
    Commented Jan 31, 2017 at 9:38
  • 1
    $\begingroup$ To sympathize a bit with @chris: I know it's been a while, but I still consider versions 6 and above as "recent"... :D $\endgroup$ Commented Jan 31, 2017 at 9:40
  • $\begingroup$ Well, version 5 and earlier converted Graphics to PostScript, which was rendered by a separate process (not by the front end). We did not have rotatable 3D graphics or high quality 3D rendering. We also didn't have antialiasing, but that could be fixed by using Ghostscript to render the PostScript. $\endgroup$
    – Szabolcs
    Commented Jan 31, 2017 at 9:41
  • 1
    $\begingroup$ @chris I'm sorry, I haven't done this in years ... I really don't remember the details. I would also have to start from scratch. I agree that it is a pain to do this. Wikipedia has some hints. Wolfram should provide more documentation on this and preferably even ship Xvfb with Mathematica (if the license allows) along with a method to use it automatically. $\endgroup$
    – Szabolcs
    Commented Jan 31, 2017 at 9:46

Sometimes you might need to tell the system directly where the mathematica kernel is situated if it is not connected to the "math" command already (I had to set that up on my macbook manually, too).

Here is a good tutorial on that: http://reference.wolfram.com/language/tutorial/WolframLanguageScripts.html

  • 1
    $\begingroup$ Thanks for our answer. However the issue is not with finding the kernel. My script runs all right but fails at the display stage. $\endgroup$
    – chris
    Commented Jan 30, 2017 at 20:43
  • $\begingroup$ What exactly do you want to display? In the kernel without the front end I don't think you can run the pl= Plot[x,{x,0,1}] line to get a visual output. But in you minimal code there is also a ";" in the end which prevents the graphical output. But shouldn't you get the .eps export from the kernel which you can open? $\endgroup$
    – Rico
    Commented Jan 30, 2017 at 20:46
  • $\begingroup$ Hm i just tested it on my university server and I received the .eps file output with your code just using the kernel via math -script test.m. Are you sure the correct kernel is linked to the "math" function? I tried it with mathematica 10 as well as 11. $\endgroup$
    – Rico
    Commented Jan 30, 2017 at 20:59
  • $\begingroup$ No im not exporting DISPLAY. It should not be needed if you just run the kernel and not the GUI of mathematica?! $\endgroup$
    – Rico
    Commented Jan 30, 2017 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.