The easiest way is to modify $Path
to include the directory you placed your packages into. Suppose your packages directory is in the Dropbox\Documents\myPackages
folder inside your home
directory; then you can add it to your path like this:
AppendTo[$Path, ToFileName[{$HomeDirectory, "Dropbox", "Documents", "myPackages"}]]
(EDIT: amended according to advice by Steve Luttrell)
To make this change permanent, you can add this line to your init.m
file.
Each system (home and work PC) will have a custom line of this sort in its init.m
file that will tell Mathematica where to look for your packages.
Please note that since you are appending the new directory at the end of the path, system directories will have the precedence over custom ones. Just in case you decide to have the same names for different packages.
If you want your packages to have the precedence, you have to change the order your directory appears in your $Path
either by prepending it or by placing it at a custom position.
And now, for something extreme...
If you really want to have Mathematica look elsewhere for all its files, you might want to fiddle with $UserBaseDirectory
. I have no experience with that, but the documentation says that "the value of $UserBaseDirectory
can be specified by setting the operating system environment variable MATHEMATICA_USERBASE
when the Mathematica kernel is launched. It cannot be reset from inside the kernel". I guess that by copying the actual userbase directory to your new Dropbox location and then by specifying MATHEMATICA_USERBASE
accordingly in your OS environmental variables, you can get Mathematica to work directly with files in the Dropbox folder. But this is something you can do only on machines where you are an administrator, and it looks kinda risky...