Help Topic: Getting Emacs in GNU/Linux and MacOS
Maintained by: mikerb@mit.edu Get PDF
Getting Emacs in GNU/Linux and OS X
Emacs is a very powerful text editor with support for software development. We will be using it a lot in 2.680. The first step in using emacs is getting emacs. In some cases it is already installed on your machine. This page describes how to find out for sure whether you have it installed, and if not, how to get it.
How to tell if Emacs is already installed [top]
Your machine may already have a version of emacs installed, with the full path name of /usr/bin/emacs. Verify this:
$ which emacs /usr/bin/emacs
If you get a response like the one above, you're all set. If emacs is not installed you will get a response like the one below:
$ which emacs emacs: Command not found
If you don't see the love yet, it is most likely because you really don't have emacs installed. However it is also possible that you simply don't have /usr/bin/ in your shell path. To rule this out, try the following:
$ cd /usr/bin $ which ./emacs ./emacs
If you see the above, it is simply a matter of adding /usr/bin/ to your shell path. Do this now, or see the help topic on augmenting your shell path.
Getting Emacs in Linux [top]
If you are running linux you very likely have access to a package manager such as apt-get and already know how to use it to some degree. To get emacs, you will need root priveleges. Do the following, and enter your normal login password when or if prompted:
$ sudo apt-get install emacs
See the discussion above on how to confirm whether emacs has been successfully installed, and adjust your shell path if need be.
Getting Emacs on the Mac - Flavor One [top]
If you are using a Mac there are two versions emacs worth installing. The fist one is all you really need, and may be obtained by going to http://emacsformacosx.com and follow the instructions for installing. You will need admin/root privileges for this. This will install the emacs binary in:
/Applications/Emacs.app/Contents/MacOS/
You will need to add this directory to your shell path. If you don't know how to do this, see the help topic on augmenting your shell path:
http://oceanai.mit.edu/ivpman/help/cmdline_augment_shell_path
Once this is done you can begin using emacs to create or edit a file by typing the following on the command line:
$ Emacs newfile
This will open a new window. You can quit by typing control-x followed by control-q. Or if you want to save your edits, type control-x, control-s before quitting.
You may notice that, for saving and quitting, there are nice little icons on the top of the window for saving a file, and you can select Quit Emacs from the Emacs Apple pull-down menu. Resist the temptation to use these!!!! One of the goals in introducing you to emacs is to help you become efficient. Use the keyboard method for doing your business in emacs. If you have to touch your mouse, you're probably doing things wrong/inefficiently. These inefficiencies really add up over time. Furthermore, when you inevitably need to remotely log into a robot and use emacs to edit a remote file, you won't be able to use the GUI ways of navigating emacs. The keyboard will be all you have.
Getting Emacs on the Mac - Flavor Two [top]
There is a second version of emacs I also typically install on my OS X machines. It may be redundant, but I always do it anyway, since it's easy, and I'm just comfortable having an emacs binary reside at the conventional location of /usr/bin/emacs. This can be installed with the MacPorts package manager.
$ sudo port install emacs
If you have not installed MacPorts, first see the help page on getting started with MacPorts:
http://oceanai.mit.edu/ivpman/help/osx_get_macports
This version will have the binary name "emacs" with a lower-case "e". So you will see the following on the command line:
$ which emacs /usr/bin/emacs $ which Emacs /Applications/Emacs.app/Contents/MacOS/Emacs
When you invoke this emacs, it will launch within the terminal in which it was invoked. A new window will not open. This is super convenient for a quick edit of a file. The same behavior can be achieved with the graphical emacs by invoking with the "-nw" command line option for "no window".
Page built from LaTeX source using texwiki, developed at MIT. Errata to issues@moos-ivp.org. Get PDF