Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the best way to package my Emacs installation (packages and config) so that it can quickly be installed anywhere?

Tags:

emacs

I generally write code by logging on to a remote machine (typically AWS). I have a fairly big list of packages that I use and a fairly large .emacs.el. While I can quickly install emacs on nay remote machine, I am looking for a way to "package" my emacs and house it somewhere so that I can quickly install it on any machine I login to. Whats the best way to do this?

like image 512
Nikhil Avatar asked Aug 21 '14 15:08

Nikhil


People also ask

Where are Emacs packages installed?

Packages are installed in ~/. emacs. d/elpa by default and will be set up for autoloading in this and all future Emacs sessions. After installing a package from the Package Menu, it is normally ready to go with no need to restart.

How do I manually install Emacs packages?

Load the File Manually To use the package, all you have to do is to make emacs load the file. Alt + x load-file then give the file path. Now, emacs is aware of the package. To activate, call the command in the package.

How do Emacs packages work?

Each package is downloaded from the package archive in the form of a single package file—either an Emacs Lisp source file, or a tar file containing multiple Emacs Lisp source and other files. Package files are automatically retrieved, processed, and disposed of by the Emacs commands that install packages.


2 Answers

First you would obviously bundle everything into source control (except for a private file). Bitbucket and Gitlab offer private repos.

You can see this wiki for a way to list all the needed packages in your init file. (this is actually used by Prelude)

Then I see some options.

Use Cask

Some use Cask to manage package dependencies, some do not

The Cask file lists all dependencies:

(depends-on "cask")
(depends-on "dash")
(depends-on "evil")

Use org-mode

Some write their config in org-mode and load it with a call to org-babel, which is doable in one line in ~/.emacs.d/init.el:

(require 'org)
(require 'ob-tangle)
(org-babel-load-file (expand-file-name "~/.emacs.d/myemacs.org"))

Split your config in multiple files

and some split it in multiple elisp files.

Here some nice configs worth taking inspiration from:

  • Noahfrederick uses org-mode and Cask: https://github.com/noahfrederick/dots/tree/master/emacs.d
  • Purcell uses multiple elisp files where each require the needed package: https://github.com/purcell/emacs.d/tree/master/lisp

In init-elpa.el, he defines a function that takes a package in argument and installs it if it is not present:

 (defun require-package (package &optional min-version no-refresh)
    "Install given PACKAGE, optionally requiring MIN-VERSION.
    If NO-REFRESH is non-nil, the available package lists will not be
     re-downloaded in order to locate PACKAGE."
  (if (package-installed-p package min-version)
  t
  (if (or (assoc package package-archive-contents) no-refresh)
  (package-install package)
  (progn
  (package-refresh-contents)
  (require-package package min-version t)))))

and in every file, he uses:

(require-package 'dired+)

Also commit the installed packages

And for your config to install quicker, you may add the installed packages into source control too. That way you can also ensure to have identical environments.

like image 164
Ehvince Avatar answered Oct 21 '22 10:10

Ehvince


I always recommend putting the entire ~/.emacs.d under version control, including all packages and other libraries.

It's a bit more hassle, and maybe a bit messier, but if you want to guarantee the state of the configuration every time you install it somewhere new, you need to have a complete copy.

Using version control is my firm preference, because that makes it trivial to revert changes to packages, etc. So if you upgrade a package and Emacs breaks, it's a single step to put things back they way they were (and doing so doesn't require you to remember how they were).

With this approach the act of cloning a single repository is all that is required to obtain a working system in a known state; and it limits your dependence upon the availability, consistency, and permanence of remote sources to just that one repository (and if you have it locally, or even carry a copy with you, you have no remote dependencies at all).

That said, lots of people don't bother and don't experience any issues, so it's not a critical point for most people.

like image 20
phils Avatar answered Oct 21 '22 10:10

phils