11

I want to use several emacs configurations/versions simultaneously so that no configuration disturbs each other, each with their own configuration directory and elpa repository. I heard about the trick with symlinking ~/.emacs.d and ~/.emacs, but that is not what I want, because it'd be best if I can run my default emacs installation and simultaneously a testing installation (new emacs releases) or another setup like Spacemacs or Prelude.

Is there any decent way to do this?

  • Related: [How to start emacs with a custom user-emacs-directory](https://emacs.stackexchange.com/q/4253). – phils Oct 24 '17 at 22:13

3 Answers3

7

I just did that using chemacs.

Considering you don't have an .emacs file in your home folder you can follow this instruction to install it:

Clone the Git repository, and run install.sh

$ git clone https://github.com/plexus/chemacs.git
$ cd chemacs
$ ./install.sh

you should get this message:

OK      Creating symlink ~/.emacs -> /home/arne/chemacs/.emacs

If you already have an .emacs file, rename or move it somewhere.

Next step, create the file: .emacs-profiles.el in your home folder:

$ touch .emacs-profiles.el

Here is an example of the this file:

(("default" . ((user-emacs-directory . "~/.emacs.d")))
 ("spacemacs" . ((user-emacs-directory . "~/spacemacs"))))

Mine looks like this:

(("default" . ((user-emacs-directory . "~/.emacs.d"))) ;; DoomEmacs, my default emacs
 ("prelude" . ((user-emacs-directory . "~/emacsprelude/.emacs.d"))) ;; Prelude
 ("goodemacs" . ((user-emacs-directory . "~/myemacs/.emacs.d")))    ;; my own config
 ("spacemacs" . ((user-emacs-directory . "~/spacemacs/.emacs.d")))) ;; Spacemacs

Here I create the file ~/myemacs/.emacs.d/init.el, for my own config.

Now to use a config, I run one of the following command:

$ emacs --with-profile 
$ emacs --with-profile myemacs 
$ emacs --with-profile prelude
$ emacs --with-profile spacemacs 

Hope this help.

Update:

There is a newer version of chemacs called chemacs2.

Update 2: Emacs 29 has now this feature built-in.

Asme Just
  • 384
  • 4
  • 13
2

I wanted the same and stumbled across a tip at the Spacemacs Github site, so I came up with the following script, which assumes that alternate configurations are stored in ~/alternate-emacsen/NAME-OF-CONFIG. I use this eg. to test emacs26 pre-release while working with a plain emacs25 and being able to use spacemacs, doom emacs or any variant configuration whenever I want to.

The script resides in ~/bin and assumes that <name-of-config> and the name of the softlink which calls it are identical; eg. if you want to launch the config stored in ~/alternate-emacsen/deepin-emacs you need a softlink ~/bin/deepin-emacs.

Be sure to put .emacs.d inside the <name-of-config> directory since the latter is used as a fake home directory, so that the actual ~/.emacs.d and ~/.emacs do not get touched.

If you think this is useful or suits your needs, feel free to use it.

#!/bin/bash

# alternate-emacsen ––  A bash  script to launch  Emacs in  completely different
#                      configurations,   like   GNU   default,   Deepin   Emacs,
#                      Spacemacs, CL  server,… from  their own  config directory
#                      trees.
# Usage:
# – create  a  directory  $HOME/alternate-emacsen/name-of-config,  containing  an
#   .emacs.d with all the base configuration  inside it.  Put the init file into
#   <name-of-config> if necessary.
# – create a link  to this script, eg.
#           ln -s $HOME/bin/alternate-emacsen.sh $HOME/bin/emacs-unstable
#           ln -s $HOME/bin/alternate-emacsen.sh $HOME/bin/spacemacs
#           ln -s $HOME/bin/alternate-emacsen.sh $HOME/bin/doom-emacs
#           ln -s $HOME/bin/alternate-emacsen.sh $HOME/bin/deepin-emacs
#           ln -s $HOME/bin/alternate-emacsen.sh $HOME/bin/prelude-emacs
#           ln -s $HOME/bin/alternate-emacsen.sh $HOME/bin/emacsstarterkit
#           ln -s $HOME/bin/alternate-emacsen.sh $HOME/bin/exwm
#           ln -s $HOME/bin/alternate-emacsen.sh $HOME/bin/clemacsd
# – set  $emacsbin below to   the  emacs  version  you  prefer/use.  or   set  it  to
#   /usr/bin/emacs  for  the  system's  default.   I  use  emacs-25.2  with  the
#   Athena/Lucid X widget set  as my default GUI (not GTK because  I do not like
#   it for several reasons), so it is set as default.
# – edit the  emacs2x entries to reflect  your preferences like in  the previous
#   step.

self="emacs config launcher";
emacsconfig=`basename -- "$0"`;
userhome=$HOME;
HOME=$HOME/alternate-emacsen/$emacsconfig;

test -d "$HOME" || { \
             echo >&2 "$self: ERROR –– $HOME does not exist!";
             exit 1;
};

# On my system, Emacs 23.2/GTK2 (in /usr/bin) is the default, but I prefer Emacs
# 25  with pure  X11  Lucid interface.   Also, the  system  default uses  partly
# incompatible ELisp packages (both to Emacs 23  and Emacs 25), so I ignore them
# by not using /usr/share/* at all (the  other Emacsen are compiled to reside in
# /usr/local and thus ignore the outer /usr tree).
emacsbin=/usr/local/bin/emacs-25.2-lucid;
sysdefaultemacs=/usr/bin/emacs;
emacs23=$sysdefaultemacs;
emacs24=/usr/local/bin/emacs-24.4-lucid;
emacs25=/usr/local/bin/emacs-25.2-lucid;
emacs26=/usr/local/bin/emacs-26;
emacstesting=$emacs26;

case $emacsconfig in
    spacemacs|deepin-emacs|clemacs|doom-emacs|prelude-emacs|emacsstarterkit)
       emacsbin=${emacs25};
       ;;
    exwm)
       emacsbin=${emacs24};
       ;;
    emacs-testing|emacs-unstable)
       emacsbin=${emacstesting};
       ;;
    *)
       HOME=$userhome;
       ;; # use emacsbin as defined in the settings
esac

export HOME;
unset userhome;
cd "$HOME";
if test -e "$emacsbin"; then
    $emacsbin "$@"
else
  echo >&2 "$self: ERROR –– not found: $emacsbin";
  exit 1
fi
  • 1
    I don't think an image is useful here, but if you want to put one, you can (and should) use the image upload button (or Ctrl+G) in the editor here. This uploads to a site that's associated with Stack Exchange so the images don't disappear when an image host goes under. – Gilles 'SO- stop being evil' Oct 25 '17 at 09:49
  • 1
    I was a bit hesitant, too, and still not convinced to do it. But thanks for the key combo –– I didn't find anything except for the option of embedding an image link. –  Oct 25 '17 at 12:56
  • @gilles: thanks for the edit, by the way, with the right tags it looks much nicer (I admit that I was too lazy to try the code tag) ;-) –  Oct 25 '17 at 13:10
-1

I would recommend using docker to setup multiple versions. This would mean you need docker installed. Docker is used to build containers, which are light-weight isolated virtual environment running on your machine.

Containers have complete isolation from your current machine therefore allowing you to set up isolated environments for each version of emacs. If you are familiar with python virtual environment, it is the same but more generic and may require more technical understanding. It may be worth the investment to learn docker.

Here is the link to dockerfile use to build images... https://github.com/Silex/docker-emacs

Good luck!

phage
  • 99
  • 2
  • Can you say why you recommend that? So far, the answer is essentially a link-only answer, so it risks being deleted. Please consider presenting specific reasons why your recommendation answers the question. – Drew Mar 03 '21 at 22:25