- Saturday, December 09, 2006
Installing Emacs on most platforms is a common and well supported operation. On Linux, for example, it's typically installed via the package management system for the particular distribution you've chosen. This hack covers installing Emacs on Windows, where it's a bit more challenging.
There are some shortcuts to getting Emacs installed and running on Windows, but we're going to walk through the steps from scratch. There are a number of "decision points" throughout the installation. When we reach those, I'll give a specific recommendation as well as provide you with the alternate options.
The first decision greets us before we even embark on the installation process. There are two primary flavors of Emacs -- GNU Emacs, and XEmacs. The former is the "original" Emacs, and the latter was branched from an earlier version of GNU Emacs by a company called Lucid. If you're interested in the history, Wikipedia has a nice summary.
I've used both versions extensively and had similarly positive experiences with each. I'm going to recommend installing GNU Emacs, however, since in my experience it seems to be the more popular version. Because it's more common, it's more likely that additional packages and snippets that you adopt after the installation will be more compatible. Future posts in this "hacks" series will also assume that you're running a flavor of GNU Emacs.
OK, so we've decided to install GNU Emacs. However, we're not quite finished yet. There are several versions and packagings of Emacs (yes, even when we limit our target platform to Windows), and so we've got yet another decision to make. Currently, the "stable" version which is distributed by GNU officially is version 21.x. The next version of Emacs, 22.x (and the version after that, 23.x), can be had by compiling your own version from CVS (there are also unofficial binary builds).
I'm going to walk you through the steps of installing the official, stable distribution of Emacs (21.x). If a newer version is distributed by the time you end up reading this, the steps are likely to be identical. Many of these steps will also be relevant for unofficial distributions, so it's a good place to start even if that's where you end up.
Before we bother to even find the official binary distribution of Emacs, though, we need to make sure our Windows environment is set up properly.
Home is Where the Files Are
As you use Emacs, it will occasionally need to read and write files to your hard drive to keep track of various settings and customizations (we'll cover many of these in this "hacks" series). The primary customizations are placed in a file called
.preceding the name causes the file to be "hidden" on Unix file systems). On Unix and Linux systems, this file is placed in the "home" directory, a user-specific location denoted by the
HOMEenvironment variable (e.g.
Windows does not set the
HOMEenvironment variable by default, so Emacs assumes that your "home" directory is
C:\. This is generally not a good place for user-specific settings. On most Windows systems, you need administrative privileges to write to the root directory. Also, multiple users on a given Windows system would likely want their own configurations. Lastly, many Windows backup and migration tools only save the contents of user-specific directories.
Fortunately, it's a simple matter to tell Emacs where our real "home" directory is -- we simply need to set the
HOMEenvironment variable. I strongly suggest using the value of the
USERPROFILEvariable as the basis for setting
HOME. This variable is always available and is properly set to the real "home" directory of the current user.
We can temporarily set environment variables from the console using the
setcommand, but we need to make this particular variable persistent. If you're using Windows Vista, you can set persistent environment variables using the
setxcommand (you can also do this on Windows XP if you install the necessary support tools). To set
HOMEfrom a normal user console session using
setx HOME "%USERPROFILE%"
If you don't have the
setxcommand, you can set this variable using a graphical tool. Choose
Systemfrom the Control Panel menu, click the
Advancedtab, and press the
Environment Variablesbutton. In the
User variablessection, add a new environment variable with the name
HOMEand the value set to your user profile directory (e.g.
C:\Documents and Settings\Derek). You can type
echo %USERPROFILE%from a command prompt to get the correct value.
To test the value, start a new console session, and type
echo %HOME%. On Windows XP, for example, you should see something like this:
Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Documents and Settings\Derek>echo %HOME% C:\Documents and Settings\Derek
Getting the Distribution
With that out of the way, we can download Emacs. Begin by visiting the official Windows distribution site. You'll notice a number of different files here:
- This contains Emacs binaries without any precompiled Lisp files. You could install Emacs with this file, but it wouldn't be very useful (you would have to add / compile the Lisp files yourself to make Emacs useful).
- The is a full installation of Emacs with precompiled Lisp files. This is a good choice if you just want to install Emacs and use it.
- This is functionally the same as the previous item, but includes the full Lisp source in addition to the compiled versions. This is the best choice if you want to be able to see the actual code behind much of Emacs. If you have the space, I recommend installing this version.
- This is the "Library of Emacs Input Methods" package, which is used for entering non-ASCII characters. You can probably skip this for now.
- This file contains the Lisp source for the Emacs distribution. If you installed the regular binary version, you could use this to turn it into the "fullbin" version.
- This version contains a special executable you can use to rebuild Emacs after changing built-in files. You almost certainly don't need this.
- This file contains the load history for built-in libraries. This file comes with the normal distributions, so you can safely ignore it.
The installation process is the same whether you install "bin" or "fullbin", so download whichever option makes more sense for you.
Because the files are in gzipped GNU Tar format, you cannot extract them using the built-in compression tool in Windows. If you already own a commercial compression tool such as WinZip or WinRAR, you can easily extract the binaries using one of those tools. If you don't have one of these tools, I recommend installing 7-Zip, which has similar capabilities and is completely free.
The root of the binary distribution contains a single directory,
emacs-21.x. Because there are no user-specific files in the binary distribution, it makes sense to install it in a shared location. If you have administrative privileges, I suggest extracting it to your "Program Files" directory (type
echo %ProgramFiles%from a command prompt to get the full path). Users with no administrative privileges whatsoever can install Emacs in their
If you're using 7-Zip, open it and navigate to the downloaded file. If you're using Windows Vista or are running as limited user account, you will need to start 7-Zip using the "Run As" feature of your particular flavor of Windows. If you don't, it won't have access to write to the shared directory. Once you've opened the downloaded file using 7-Zip, double-click
[Content], select the
emacs-21.xdirectory, and click
Extract. Enter the full path to your "Program Files" directory, and click "OK".
You can now close 7-Zip, navigate to your "Program Files" directory and confirm that the extraction was successful.
You now have a usable version of Emacs. If you execute
bindirectory, Emacs will open and be fully functional. This isn't the most convenient way of starting Emacs, however. Thus, there is one last installation step.
bindirectory containing the
runemacs.exefile, there is a file called
addpm.exe. This file "installs" Emacs by adding a start menu program group and adding a few registry entries in
HKEY_LOCAL_MACHINE\SOFTWARE\GNU\Emacs. Simply double-click the file, click "OK", and Emacs will be fully installed. Now you can open Emacs from the "Gnu Emacs" program group in your start menu.
Now that Emacs is installed, feel free to start using it. If you're accustomed to Windows editors, chances are it will feel a bit strange at first. Perhaps the most useful thing you can do at this point is to invoke the Emacs Tutorial (click the
Helpmenu item to access it). This will cover some of the basic Emacs commands and concepts. If you complete the entire tutorial, you should start to feel comfortable enough in Emacs to do some basic editing. Practice using the Emacs commands as much as you can afford to. You'll learn hundreds of them over time, but the commands covered in the tutorial are some of the most important ones.