I alternatively run 24.5 and 25.0.50. Unfortunately, packages installed and compiled from 25.0.50 don't work with Emacs 24.5 (cl-struct-define is a common culprit).

One trivial solution is to not byte-compile anything. That makes things pretty slow, though.

How can I use compiled packages (for performance) while using the same .emacs.d for both 24.5 and 25.0.50? I'd also be ok with 24.5 ignoring the compiled files.

  • This question is similar, but not exactly the same: it focuses on easily keeping a bunch of versions side by side for testing purposes, but it doesn't discuss byte-compiled files at all.
    – Clément
    Commented Jun 18, 2015 at 0:14
  • 3
    I set package-user-dir and few other dirs and files based on emacs version. I can write a detailed answer when I am at a computer. Commented Jun 18, 2015 at 1:28
  • @kaushalmodi: Won't that force me to install each package twice?
    – Clément
    Commented Jun 18, 2015 at 8:28
  • Yes. Each package is installed multiple times (and each installation folder will have that emacs version specific byte compiled files). But you don't do that manually. I maintain an alist in my init.el and all those packages are auto-installed on emacs startup (if not already installed). You can even use the :ensure keyword of use-package to auto-install packages. Commented Jun 18, 2015 at 11:07

2 Answers 2


Put the byte-compiled files for different Emacs versions in different directories. Make your load-path conditional on the Emacs version you are running, so that you load the appropriate byte-compiled libraries.

  • 2
    (IMO, it's too bad that Emacs dev no longer makes an effort to maintain forward compatibility for byte-compiled files. It used to be the case that you could use a library compiled using an older version in a newer version. You might not have been able to take advantage of a few new features, but generally there was no problem. This is still the case for most things, but for less and less, unfortunately.)
    – Drew
    Commented Jun 18, 2015 at 1:14
  • Thanks, that's a nice idea. Is there a way to make the package manager put elc files in that version-specific directory though? Some sort of default destination for byte-compile-file maybe?
    – Clément
    Commented Jun 18, 2015 at 8:26
  • Dunno; sorry. Someone else will hopefully answer that question. I'm not an expert on the pkg mgr. I would think (&hope) that the answer is yes, that it provides an easy way to do that.
    – Drew
    Commented Jun 18, 2015 at 13:40

It is perfectly possible to have packages.el put byte-compiled code into versioned subdirectories of the elpa package. This gives a structure like this:

┌ elpa
└┬ the-package-date.time
 ├─ the-package.el
 ├┬ 23.4
 │└─ the-package.elc
 ├┬ 26.3
 │└─ the-package.elc
 └┬ 27.1
  └─ the-package.elc

The load path is constructed in such a fashion, that the versioned directory appears before the source directory, e.g.:

  ;; ...

To accomplish all of this, I have just written the package package-compat, which uses mostly adviced functions to provide that feature for Emacs 23 to Emacs 27.

The package mechanism is just used for distribution in this case, since the code must be loaded before any packages are activated and/or installed.

Either add "https://almost-un.org/selpa/packages" to the variable package-archives

(add-to-list 'package-archives ("almost-un.org" . "https://almost-un.org/selpa/packages/") t)

and download the package with (package-install 'package-compat) or download the tar(1) archive from the above page.

Then follow the instructions in any of the Emacs lisp files.

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.