Quick tip: changing the userbase directory in Mathematica (Linux)

Recently, I came across the problem of readdressing the Mathematica user folder for a sort-of-portable version of Mathematica. In Linux this folder resides in the user’s home directory as ~/.Mathematica and contains all user defined settings as well as additional packages. Its contents can grow quite large over time and there are situations where you want to outsource it (maybe to an USB flash drive) or simply have in a non-default location (maybe relevant for virtual machines). Redirecting ~/.Mathematica to another place by a symbolic link is not always an option. The only documented possibility is to set an environment variable called MATHEMATICA_USERBASE with the desired location as value and then run Mathematica. This works and here is my quick tip on how to make it more or less permanent. In Linux Mathematica is started by a shell script (called Mathematica) inside the Executables folder relative to the installation directory. What I wanted (in my case) was to move the user folder inside the installation one. Funnly enough, it can be done with no effort. Just open the file Executables/Mathematica in a text editor and got to the very end and add

UsrBaseDir="${TopDirectory}"/.Mathematica
export MATHEMATICA_USERBASE=${UsrBaseDir}

right before the

"${MathematicaFE}" -topDirectory "${TopDirectory}"  "$@"

line. Done. Notice that ${TopDirectory} is derived in the rest of the script and I cavalierly reused it here. You can modify UsrBaseDir=/path/to/your/folder to customize it for your needs. I tested it with Mathematica 8 and 9 and it also works for the command line version Executables/math and the other executables.

Advertisements

About goobypl5

pizza baker, autodidact, particle physicist
This entry was posted in Mathematica and tagged , , . Bookmark the permalink.

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s