Relocatable emacs

compilingemacs

Is there a way to build emacs on Linux so it doesn't embed the path where it was built into the binary, and it can be relocated harmlessly to a different path?

That is, if you build with --prefix=/a/b/c then move everything to /d/e/f it won't run, because it depends on the fixed path /a/b/c. I see the string /a/b/c inside the binary itself.

Windows emacs can be installed to any directory and it runs from there just fine, so it makes me think you can tell Linux emacs to run the same way, from "wherever you are sitting now".

We have no options like a fixed name symlink up the directory tree pointing to the variable path below it.

Best Answer

Emacs can be relocated mostly harmlessly, even if you don't take any precautions when compiling. If the hardcoded paths don't work, Emacs looks for directories near the executable.

Emacs tries to determine where the executable that invoked it is located. It stores this information in the variable invocation-directory. Let's say that this is /path/to/bin/emacs; Emacs looks for the data files it needs in the hard-coded directories, and falls back to directories in /path/to.

You need to structure your directories in the same way as the Emacs source, more or less, with toplevel directories bin, etc, leim, lib-src, lisp, site-lisp. In particular, at least with Emacs 23.2, the directory lib-src must exist (even if it's empty).

There are a few directories that Emacs doesn't find this way. Set the environment EMACSDATA=/path/to/etc. You may need to set INFOPATH as well.

Related Question