Next-generation package management with straight.el
After a long and frustrating struggle to use package.el
+ Quelpa to manage my packages, I bit the bullet and wrote my own package manager. It is intended to completely replace package.el
by providing a package management experience that is superior in almost every way.
You can read the very extensive documentation to learn about all of its features, but the most relevant one to this question is that straight.el
focuses on perfect reproducibility. This means it should not matter whether you are starting Emacs normally, or starting it on a new machine, and that any local changes are version-controlled and can be reverted to a canonical state. Practically speaking, this is achieved by (1) cloning packages as Git repositories, and providing automated tools for managing their state; (2) using the init-file as the sole source of truth for package management state, with no mutable data stored elsewhere; and (3) using optional version lockfiles to specify exact Git revisions of every package, plus any recipe repositories and straight.el
itself.
To get started, insert the bootstrap snippet, which will install and activate straight.el
. Then, to ensure that a package is installed, simply place a call to straight-use-package
in your init-file:
(straight-use-package 'projectile)
Yes, it's that simple. No dealing with package-refresh-contents
or any of that garbage. If you remove this form from your init-file and restart Emacs, Projectile will no longer be loaded (unlike in package.el
). This means you do not have to worry about your configuration somehow not working on a new machine because you accidentally depended on undeclared packages.
You can install packages whereever and whenever you would like, throughout your init-file (no need to declare a list of them at a single point). Of course you can also just do
(dolist (package '(ace-jump-mode ... zzz-to-char)) (straight-use-package package))
if you prefer the list. I however recommend that you use use-package
to manage your package configuration. First you have to install it:
(straight-use-package 'use-package)
Then, since straight.el
has built-in integration with use-package
, the following "just works":
(use-package projectile
:straight t
:init (projectile-mode 1))
Once you've written your init-file to install the packages it needs, run M-x straight-freeze-versions
to save a version lockfile to ~/.emacs.d/straight/versions/default.el
. You should keep this file under version control, since it will allow straight.el
to check out the correct versions of all your packages, when you first launch Emacs on a new machine. (You can manually revert to the versions specified in the lockfile using M-x straight-thaw-versions
.)
To support the idea of machine-local dotfiles that I mentioned in my other answer, straight.el
offers a profile system. I still recommend using symlinks for your dotfiles (in this case, init.el
, your local init-file if applicable, and the version lockfile if you want to use one).
If you're wondering how straight.el
compares with other package managers, check out the extensive comparisons section. But there is lots more documentation on everything else, too.
init.el
around (using git for example), this approach also works (based onuse-package
): lunaryorn.com/posts/…~/.emacs.d
directory, so use whatever method you prefer to synchronise that between machines. (e.g. a Github repository, or a Dropbox folder, or whatever works best for you).