简体   繁体   中英

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

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?

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:

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.

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.

It would be helpful if you clarified a little more what you mean by "any" computer. It sounds like emacs already installed on the machine and you just want to configure emacs to use your packages and settings. Do you have physical access to the machine or network from which you could load files from a memory stick? If not, can you access cloud storage?

My own setup looks like this:

I have a Windows 7 machine at work and Linux Mint at home. I have a dropbox account that holds all my emacs configuration files and packages. This dropbox account is synchronized to a local folder on each machine and my .emacs file on each computer is only one line: (load-file "~/Dropbox/dotemacs.el") I often tweak package files and configurations. Using dropbox keeps my settings synchronized across all computers.

If you can't install Dropbox, you could manually sync to cloud storage like git.

check https://github.com/redguardtoo/elpa-mirror ,

create your own repository on a usb memory stick, it's stable because all the package versions are the version you are already using for a very long time.

That's the quickest way, basically you can get your setup on any machine in 1 min.

As the README for my repo emacs for rails devs says it is as easy as pushing your ~/.emacs.d contents to github and on the target machine:

  1. Install emacs using homebrew (chances are you are on OS X) brew install emacs --HEAD --use-git-head --cocoa --srgb
  2. Git clone your repo to ~/.emacs.d/
  3. Boot emacs

If there is magic, it's using the built in package manager with ELPA and marmalade and having that check to see if packages are installed and if not, install them.

Works for me and my boxes & servers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM