After installation Mathematica 8 for Linux takes more than 3GB in the /usr/local/Wolfram/ directory. I suspect that not all of it is relevant if I want to do some occasional computations. Are there subdirectories which can be deleted safely to save some space?

  • 1
    $\begingroup$ I don't know if this is safe, and I'm not going to try it here, but the SystemFiles/Kernel directory will have several subdirectories which have a 64-bit and a 32-bit version. If you are using a 32-bit system, you might try deleting the 64-bit versions. It should save a few hundred MB. $\endgroup$
    – Szabolcs
    May 29, 2012 at 19:44
  • 8
    $\begingroup$ If you have the (up-to-date) Java runtime installed separately to Mathematica, you could delete the copies of the JRE in SystemFiles/Java/<$SystemID>. I did this not so much to save space but because the versions Mathematica installs are never updated, and old versions of the JRE have serious security vulnerabilities. (And Java 7 is much faster than Java 6, so there might be some performance benefit.) I checked the Java 7 release notes to make sure there weren't any major incompatibilities before doing this and haven't had problems so far, but YMMV. $\endgroup$ May 30, 2012 at 0:37

5 Answers 5

  1. You can save a lot of space in the Documentation directory by using Delete All Output on all the larger ones and by using disk compression. For example, the v7 documentation Notebook for ContourPlot is 27.7MB, but after deleting output it is only 192k, and after NTFS compression only 72k. Doing this will require evaluating the documentation page before you can see the examples, but it will easily save 500MB for version 7; probably more in later versions.

    You can modify this answer as per your needs to programmatically delete all the output cells from the notebooks in the Documentation directory.

  2. As Oleksandr suggests you can delete the SystemFiles/Java/<$SystemID> folder(s), which contain copies of the JVM, if you have Java installed separately, saving about 190MB of space. (Or, following point #3, about half that.)

  3. Initial testing indicates that core functionality is retained after deleting binaries for the other system type (32 or 64 bit) from SystemFiles\Kernel\Binaries, SystemFiles\FrontEnd\Binaries and SystemFiles\Converters\Binaries saving about 88MB for version 7.

Under Windows you can use WinDirStat to easily visualize the space allocation within a drive or directory tree. That page recommends KDirStat for Linux and Disk Inventory X for OS X.

  • 5
    $\begingroup$ It's worth noting that SystemFiles/Java also contains some JAR files that might be needed (e.g. for activation of Mathematica after installation), so my suggestion isn't to delete this entire directory, but just the JVMs (which are in subdirectories named after the $SystemID they correspond to). I've edited accordingly. +1 for the suggestion wrt. the documentation, BTW--seems like both the safest and most effective option here. $\endgroup$ May 30, 2012 at 3:15
  • $\begingroup$ @Oleksandr thanks for the fix; quite important! $\endgroup$
    – Mr.Wizard
    May 30, 2012 at 7:01
  • $\begingroup$ WinDirStat is a nice program, but it's first-time run takes incredibily long. I seem to recall something like half an hour or so on a PC I installed it on last year. $\endgroup$ May 30, 2012 at 10:07
  • $\begingroup$ @Sjoerd you mean for doing all files on the disk? Or some kind of self-compile? I cannot recall such an event. $\endgroup$
    – Mr.Wizard
    May 30, 2012 at 10:09
  • $\begingroup$ Yes, all files on a disk. Something like 250 GB of files on a 350 GB disk in a 4 year old PC. $\endgroup$ May 30, 2012 at 10:11

Half of it appears to be in ../Documentation , you could delete that and look everything up on the Wolfram site on the web


Since Windows doesn't display directory sizes for me I wrote a tiny utility to let Mathematica display them in a collapsible tree form (code at the bottom).

I opened up some candidates for deletion, but you should try them first by moving the specific directories out of the MMA directory structure. As Image_doctor said, the documentation is a good sized candidate, as well as the 32/64 bit versions of the binaries suggested by Szabolcs. Further candidates can be found in the Links directory (but don't touch the MathLink directory; many of the others are probably safe, but no guarantee).

Mathematica graphics

directoryTree[startDir_] :=
 Module[{names, dirs, files, sizeFiles, sizeDirs, sons},
  names = FileNames[];
  dirs = Select[names, (FileType[#] == Directory &)];
  files = Complement[names, dirs];
  sizeFiles = Total[FileByteCount /@ files];
  sons = If[Length[dirs] > 0, directoryTree /@ dirs, {}];
  sizeDirs = If[Length[sons] > 0, Total[sons[[All, 2 ;; 3]], 2], 0];
  {startDir, sizeFiles, sizeDirs, sons}

dirTreeView[{}] := ""
dirTreeView[dT_] := 
     Row[{First[dT], " (", Length[dT[[4]]], ", ", Total@dT[[2 ;; 3]], ")"}], 
     Column[dirTreeView /@ dT[[4]], Frame -> All]

  • 1
    $\begingroup$ Also, if the OP cared for it, they could probably make it such that all hyperlinks to paclet:ref/Foo are replaced with http://reference.wolfram.com/mathematica/ref/Foo.html, so that Information (?) would take them directly to the page in a browser instead of giving an error (if they deleted the docs). The stored paclets used in ExampleData could possibly go too... $\endgroup$
    – rm -rf
    May 29, 2012 at 22:31

In general, you can delete directories that correspond to settings of $SystemID other than what you use. For example, I could delete the contents of


since Mathematica on my machine has "MacOSX-x86-64" as its $SystemID, so it will use the files in


Additionally, as an extreme measure, on OS X MathKernel is a universal binary:

> file MathKernel 
MathKernel: Mach-O universal binary with 2 architectures
MathKernel (for architecture i386): Mach-O executable i386
MathKernel (for architecture x86_64): Mach-O 64-bit executable x86_64

and you can use lipo(-suction, I presume) from a command line to thin it down:

lipo -extract i386 -output MathKernel32 MathKernel
lipo -extract x86_64 -output MathKernel64 MathKernel

and then rename the appropriate bitted kernel to MathKernel. On my system, this would save about 70 MB.


As a supplement to the other answers, here's a code sample that deletes output from the documentation notebooks. Put this in an .nb file, save it, and run it - I've tested using Mathematica 10.4. You will need to ensure the documentation notebooks are writable by the user account under which you're running Mathematica while the script runs.

There is a fairly significant catch: in my tests, this crashes the front end. Repeatedly. Every ~200 files, on average. To help work around this, every 20 files the code prints out the number of files it's processed so far, and then saves itself. That way, when it crashes, you can open up the notebook, look at the last printed output, and adjust the first argument of stripDocs to match so you can pick up where you left off. I realize this is far from ideal, but in the absence of any specific code in the other answers, I figured it would be useful.

directoryTreeRecursion[startDir_] := Block[
  {names, dirs, files, sizeFiles, sizeDirs, children},
  Sow[startDir, "directory"];
  names = FileNameJoin[{startDir, #}] & /@ FileNames[];
  dirs = Select[names, (FileType[#] == Directory &)];
  files = Complement[names, dirs];
  Sow[#, "file"] & /@ files;
  children = 
   If[Length[dirs] > 0, directoryTreeRecursion /@ dirs, {}];
directoryTree[startDir_] := Reap[directoryTreeRecursion[startDir]][[2]]

stripOutput[filename_, mode_: "Notebook"] := Block[{},
   (*advise against using this, it will close the current notebook*)
     FrontEndToken["Open", filename],
    nb = NotebookOpen[filename, Visible -> False];
    NotebookDelete[Cells[nb, CellStyle -> "Output"]];
   Message[stripOutput::mode, mode];
stripOutput::mode = "`1` is not a valid mode; only \"Kernel\" or \"FrontEnd\" is recognized."; 

doclist = directoryTree@FileNameJoin[{$InstallationDirectory, "Documentation"}];
docnblist = Select[doclist[[2]], StringEndsQ[#, ".nb"] &];

timeFormat[seconds_] := Block[
  {h = Floor[seconds/3600], m = Mod[Floor[seconds/60], 60], 
   s = Mod[seconds, 60]},
   If[h > 0, "`1`:`2`:`3`",
    If[m > 0, "`2`:`3`",
   {h, If[m < 10, "0" ~~ ToString[m], m], 
    If[s < 10, "0" ~~ ToString[s], s]}

stripDocs[min_, max_] := Block[
   numberTemplate = 
    StringTemplate["Currently processing `1` of `2`"],
   timeProgressTemplate = 
    StringTemplate["`1` elapsed, `2` estimated remaining"],
  startTime = AbsoluteTime[];
   For[i = min, i <= max, i += 1,
    fn = docnblist[[i]];
     Mod[i, 20] == 0,
     ProgressIndicator[Dynamic[i], {min, max + 1}, 
      ImageSize -> {500, 20}],
     numberTemplate[i - min + 1, max - min + 1],
     With[{t = AbsoluteTime[] - startTime}, 
       timeFormat@Ceiling[(max + 1 - i)/(i - min + 1) t]]],

stripDocs[1, Length[docnblist]]

Parts of this code were adapted from Sjoerd's answer and, on another question, Szabolcs' answer, István's answer, and bobknight's answer

  • $\begingroup$ Many thanks! This ran on my linux-x86-64 copy of Mathematica 11.3, crashing only once around file 13000 of 13500 or so. To make the files writable, I ran sudo chmod -R 777 on the Documentation directory, afterwards reverting to 755. The directory went from 5.1Gb to 2.0Gb. $\endgroup$
    – zahbaz
    Aug 24, 2018 at 7:48

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.