17

What is the proper procedure way to install new packages for Mathematica?

In particular, when you download any notebook from MathWorld, you are are given a link to Mathworld packages, which is are zip files with dozens of .m files

Where do they go?

Yaroslav Bulatov
  • 57,332
  • 22
  • 139
  • 197

3 Answers3

15

To have your packages that you've either downloaded or personally created visible to Mathematica, put them in $UserBaseDirectory/Applications, or $BaseDirectory/Applications if you want them accessible to all users on your system. Alternatively, version 8.0.4 (and likely earlier) has a menu option: File -> Install which will do it for you. The menu option brings up the following dialog

install dialog

install type drop-down displayed

item source drop-down displayed

where the option "Install for this user only (name)" would install it under $UserBaseDirectory and the "for all users" option would install it under $BaseDirectory.

For more information on where Mathematica places everything I would read this tutorial, and look through directory operations functionality.

rcollyer
  • 10,475
  • 4
  • 48
  • 75
8

If they are just temporary packages, it is often easier to load them from the current directory, but otherwise moving the files to anywhere on $Path (such as $UserBaseDirectory/Applications as suggested by rcollyer) will work although some directories are autoloaded.

My usual solution is to have

SetDirectory[NotebookDirectory[]]

as more or less the first line in all notebooks. I can then load packages from the notebook directory with Needs["foo"]`. For versioning, you can use the more verbose form of needs:

Needs["foo`","foo-001.m"] 
Janus
  • 5,421
  • 2
  • 26
  • 37
4

Under Windows it is often better to use %AllUsersProfile% directory instead of %UserProfile% for storing additional packages. The following command gives the path to the corresponding directory under Windows:

First@ReadList["!cmd /C echo %AllUsersProfile%", 
   String] <> "\\Application Data\\Mathematica\\Applications"

P.S. I think this and this answers of John Fultz are relevant.

Alexey Popkov
  • 9,355
  • 4
  • 42
  • 93
  • Please add why you believe that this is better to your answer. – Mr.Wizard Apr 25 '11 at 20:58
  • 2
    @Mr.Wizard It is a matter of personal preference. It is often easier to share all the beneficial changes for all accounts of multi-user computer, so you had no questions as to why the same work under one account, but it does not work under others. – Alexey Popkov Apr 26 '11 at 02:47