- Saturday, December 09, 2006
Emacs Hack #1: Install Emacs on Windows
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.
Which Emacs?
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
.emacs(the.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 theHOMEenvironment variable (e.g./users/derek).Windows does not set the
HOMEenvironment variable by default, so Emacs assumes that your "home" directory isC:\. 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 theUSERPROFILEvariable as the basis for settingHOME. 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 thesetxcommand (you can also do this on Windows XP if you install the necessary support tools). To setHOMEfrom a normal user console session usingsetx, type:setx HOME "%USERPROFILE%"
If you don't have the
setxcommand, you can set this variable using a graphical tool. ChooseSystemfrom the Control Panel menu, click theAdvancedtab, and press theEnvironment Variablesbutton. In theUser variablessection, add a new environment variable with the nameHOMEand the value set to your user profile directory (e.g.C:\Documents and Settings\Derek). You can typeecho %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:
emacs-21.x-barebin-i386.tar.gz- 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).
emacs-21.x-bin-i386.tar.gz- 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.
emacs-21.x-fullbin-i386.tar.gz- 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.
emacs-21.x-leim.tar.gz- This is the "Library of Emacs Input Methods" package, which is used for entering non-ASCII characters. You can probably skip this for now.
emacs-21.x-lisp.tar.gz- 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.
emacs-21.x-undumped-i386.tar.gz- This version contains a special executable you can use to rebuild Emacs after changing built-in files. You almost certainly don't need this.
fns-21.x.x.el- 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.
Unpacking
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 (typeecho %ProgramFiles%from a command prompt to get the full path). Users with no administrative privileges whatsoever can install Emacs in theirHOMEdirectory instead.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 theemacs-21.xdirectory, and clickExtract. 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.
Installing
You now have a usable version of Emacs. If you execute
runemacs.exefrom thebindirectory, 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.In the
bindirectory containing therunemacs.exefile, there is a file calledaddpm.exe. This file "installs" Emacs by adding a start menu program group and adding a few registry entries inHKEY_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 What?
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.
Comments
- Sunday, December 10, 2006 12:54:30 AM by Tom
- Sunday, December 10, 2006 1:47:27 AM by DerekMost people with enough knowledge to follow those steps don't read these sorts of posts. If I was writing the steps for an Emacs expert unfamiliar with Windows, I would say:
1. Extract the Emacs binary of your liking to a shared directory using GNU tar or similar.
2. Set your HOME directory to the value of %USERPROFILE%.
There are plenty of tutorials written to users of this level -- the length of this post is intended to provide enough background information so that someone following these steps doesn't have to find other sources of information (Why GNU Emacs vs. XEmacs? Why shouldn't I just put .emacs in C:\? etc.)
If you wrote a book on programming Java for a C++ expert, you'd surely write it differently than if you were writing it for an audience of CS students.
Yes, Emacs is (mostly) for programmers -- not all programmers are experts :) - Thursday, January 11, 2007 5:23:47 PM by JWTom, I rather think the explanation of the different binary releases is quite useful. I'm a programmer AND I want to learn emacs, but I'm severely disinterested in gambling on which release is the 'correct' one that won't kneecap me as I'm trying to learn.
- Tuesday, February 06, 2007 11:39:32 PM by Michael LudwigThanks, Derek, as a VIM user who's never really used emacs and hasn't used Windows for such a long time I found your instructions and explanations really helpful, particularly those pertaining to the different releases - this is how I found your page via Google.
- Tuesday, March 13, 2007 5:23:56 AM by AdamThanks, this really helped one student who would never have figured out how to install Emacs on his own.
- Friday, March 16, 2007 11:55:52 PM by Ed BDoes anyone know how to get diff working on windows? I installed cygwin after installing emacs, but it still can't find diff.
- Thursday, March 22, 2007 6:31:25 PM by DerekEd B, you probably just need to add Cygwin to your PATH. You can either set it in Windows, or to set it in Emacs only you can use add this to .emacs (assuming you've installed to C:\cygwin):
(setenv "PATH" (concat (getenv "PATH") ";C:\\cygwin\\bin"))
You can also fetch some native Windows versions of GNU tools here:
http://gnuwin32.sourceforge.net/ - Sunday, April 08, 2007 5:57:23 AM by ajcI wounldn't have discovered the "setx" thing (way better than the awful GUI), nor would I have known about addpm.exe ---
- Sunday, April 08, 2007 5:58:35 AM by ajcI liked the post. thanks. I wounldn't have discovered the "setx" thing (way better than the awful GUI), nor would I have known about addpm.exe ---
- Tuesday, June 05, 2007 7:10:40 PM by afYAY! setx stuff was just what i needed, and now i can save my profile!
thx. - Thursday, July 05, 2007 11:06:28 PM by LeeThank you for the wonderful "Emacs Hacks" postings. They are thorough and beautifully written, and very useful.
- Sunday, July 29, 2007 10:27:42 PM by JasonHas anyone able to "M-x shell" in Windows Vista irregardless of whether you downloaded binaries or source and build it yourself? I'm not able to with the Gnu and Xemacs binaries.
- Thursday, September 13, 2007 10:15:39 PM by JustinI gave up trying to build emacs for windows. With mingw and visual studio it just doesn't seem to work out of the box. Anyway... I've been using the binaries for a few days. Seems good so far. I haven't really got much benefit over the cygwin version. The path names and copy and pasting is slightly easier.
What I've lost though is:
etags. How do you run etags? I suppose I need to download a win32 version?
Is there way to get the nice crisp font that Putty uses into w32 emacs? - Thursday, September 13, 2007 10:58:56 PM by Derek
- Friday, September 14, 2007 3:11:54 AM by JustinThanks, I'm happy!
- Sunday, September 16, 2007 2:48:23 PM by SarahThanks for putting this up. As I would say to Captain Kirk, "dangit Jim, I'm a researcher, not a Windows administrator!" so I'm grateful for posts like this that help me get on with my work.
- Wednesday, September 26, 2007 10:46:15 PM by BharathI followed you instructions here and got EMACS set up, but for some reason EMACS is refusing to read my .emacs file. I've set the home variable and I've put my .emacs file there, but none of the stuff I put in it is taking effect.
- Wednesday, October 03, 2007 6:53:52 PM by BarryI didn't even get through unpacking the program before I encountered difficulties. 7-Zip said that it couldn't unpack all the important files. And the unpacked directory doesn't show up in Program Files. I'm using Vista, so any help would be most appreciated.
- Friday, October 19, 2007 7:21:29 AM by Gabriel NguyenI am having an odd problem. When using the cgywin package for Emacs 21.12, it installs fine. When I run the emacs command within the cgywin prompt, I see emacs INSIDE the prompt. How come it doesn't pop up a window? I have xemacs, and that pops up a window.
I will have a shot at your instructions Derek. - Monday, October 22, 2007 5:38:38 PM by MarkBarry, I am on Vista and don't want to install unnecessary stuff like 7-Zip, so I just grabbed a .zip version instead of a .tar.gz version. I recommend doing that.
- Monday, October 22, 2007 5:48:58 PM by MarkDerek,
I appreciate this blog too, in spite of being a programmer, and having used Emacs for over 20 years. I'm still getting the hang of Windows, but having Emacs available lets me amaze my colleagues with the stuff I can do in a few keystrokes....
Regarding addpm [GNU Emacs 22.1], it doesn't seem to be adding any Registry entries under the location you mentioned. I even explicitly invoked it as Administrator here on Windows Vista, but got nothing showing up there in the Registry. I'm too lazy to go get the CVS source to see what it's trying to do. I find some interesting entries, such as HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.emacs, though. Did it add that?
Also, it'd be great if you could address the whole gnuserv vs. emacsclient/emacsclientw stuff that's new to Emacs22. I'd been using gnuserv for years, and now I'm struggling to understand what to put in the Registry. - Friday, November 02, 2007 5:11:25 PM by KnightThanks ! I love your detailed instructions.. For the commenters above, this detail removes ambiguity. Dont we all hate ambiguity ? :)
- Sunday, November 18, 2007 7:16:51 AM by Matthew KimberMuchas gracias!
- Wednesday, November 21, 2007 5:43:28 PM by Jan-Henrik HorstmannPerfect! Thank you so much!
- Tuesday, January 08, 2008 3:36:48 PM by Robert InderIgnore Tom! I believe the detail is excellent, and beneficial. People can skim stuff that looks familiar. I know a lot about emacs, and not-so-much about Windows. I learnt how to set environment variables! A "detail" that I could doubtless have found in any number of places on the Web in only half an hour or so with Google...
So well done!
Robert. - Monday, February 04, 2008 1:40:12 AM by Paul McQuestenThanks for the good write-up. Anyone who complains about excessive detail in documentation is obviously an amateur.
1. Get Emacs from somewhere - 21.x is best
2. Unpack with 7-Zip
3. Set home directory
4. Put .emacs file in home directory
5. No step 5
After reading how to do this elsewhere, it turns out to really be this simple.
Adding extensions seems to be similarly verbose, and I'm guessing it's actually very easy - probably only 3 steps.