© Harley Hahn 2016

Harley Hahn, Harley Hahn's Emacs Field Guide, 10.1007/978-1-4842-1703-0_3

3. Installing Emacs

Harley Hahn

(1)Santa Barbara, California, USA

3.1 Section 3.1: Installing Software: Packages vs. Manual Installation

In this chapter, I will show you how to install Emacs with Linux, OS X, and Microsoft Windows. Before we get to the details, however, I want to discuss the various ways in which Emacs, and software in general, can be installed. Even if you already have Emacs on your computer, I would like you to take a few minutes and read this entire chapter (which is short). There are two reasons.

First, I am going to explain important concepts that I want you to understand. This is because what we will be talking about is generally applicable to installing all types of software, not just Emacs. Second, regardless of which operating system you are using, I think you will find it interesting to see how software installation differs with Unix and Linux, OS X, and Windows.

Emacs is widely available for free: all you have to do is find it and install it. There are a number of different versions of Emacs but, by far, the most widely used is GNU Emacs (see Section 1.4), and that is the version of Emacs we will be discussing in this book. However, because basic Emacs doesn’t vary much, if you are using another type of Emacs, what you learn in this book will work just fine on your system.

Emacs has been adapted to run on a very large number of operating systems. My conservative estimate is that, over the years, various versions of GNU Emacs have run on well over 100 different types of operating systems. (And when I quote you that number I am counting all the different Linux distributions as one.) As I write this (2016), the most important operating systems on which GNU Emacs is supported officially are:

  • Linux (all distributions)

  • FreeBSD

  • NetBSD

  • OpenBSD

  • OS X on the Mac

  • Solaris

  • Microsoft Windows

In most cases, you will find that installing GNU Emacs is fast and easy. However, the installation details depend on what operating system you are using. There are two basic ways to install Emacs: using a package management system, or doing a manual installation. I’d like to take a minute to discuss each of these methods briefly, so you understand how they work. Before we start, I’d like to define a few technical terms.

An ARCHIVE is a file that acts as a container for multiple files. The data within an archive is usually compressed to save storage space. When you process an archive in order to access the contents, we say that you EXTRACT the files.

Using an archive is an easy way to store and share any type of file. For instance, you might use an archive to store the full collection of all the photos you have ever taken of your cat. You could then send a copy of the archive — one single file — to your friends. Once they receive the archive, it is easy for them to extract all 739 separate cat photos to enjoy on their own computer.

The most common use of archives is software distribution. In such cases, an archive contains all the programs, data, and metadata (see below) that someone will need to install a specific program on their computer. For example, the Free Software Foundation (FSF) distributes Emacs by using archives. All you need to do is download the appropriate archive for your particular system. You can then extract the files and install them on your system (as long as you know what you are doing).

METADATA refers to information about the contents of the archive. In a software archive, metadata generally consists of helpful comments to be read by humans, as well as directory information, time stamps, file permissions, and file ownership data. You may also see information related to error detection/correction and encryption.

Generally speaking, the programs within a software archive will be either source files or binary files. SOURCE FILES contain programs that need to be COMPILED (processed) before they can be installed and used. BINARY FILES are compiled programs that are ready to run. With Unix (and Linux) systems, programs are generally distributed as source files, so they can be compiled to run on a specific system at the time of installation. Windows programs, on the other hand, can run on other Windows systems, so they are distributed as binary files, which makes the installation quicker and simpler.

With Unix, archives are most commonly created as TARBALLS. The name indicates that the archive is created by the Unix tar program. Although you will see variations, a typical tarball will have a file name that ends in .tar.gz. For example, the tarball that contains the archive for GNU Emacs version 24.5 is called emacs-24.5.tar.gz.

In this example, the tar program was used to put all the files needed to install GNU Emacs version 24.5 into a container file named emacs-24.5.tar. This is called a TARFILE. The tarfile was then compressed by the gzip data compression program to create the tarball named emacs-24.5.tar.gz.

With Windows, software archives are most commonly shared as ZIP FILES. Conceptually, a zip file is similar to a tarball, in that it is a compressed file containing a collection of other files. However, the underlying technology is different. Moreover, as I mentioned, when archives are used to distribute software, you will find that Windows zip files contain binaries, where Unix tarfiles generally contain source files.

A moment ago, I told you that an archive contains everything you need to install specific software as long as you know what you are doing. That is a big "if", because installing software manually on a Unix system requires knowledge and experience.

To make software installation faster and easier, virtually all Unix systems come with a PACKAGE MANAGEMENT SYSTEM or PACKAGE MANAGER to do the work. A package manager automates the various processes required to install, upgrade, configure, and uninstall software. All you have to do is tell the package manager what you want, and everything is done automatically.1 As a general rule, each Linux distribution uses a specific package manager. By far, the most popular ones are APT and RPM. However, you will also see Pacman, Pgktool and Portage. The various BSD versions of Unix use either pkg or pkg_add.

A package manager installs software by using a PACKAGE: a file containing an archive, as well as extra information needed to guide the installation process. There are tens of thousands of different packages, which means it is easy to download and install tens of thousands of different programs. Most packages are shared online in public REPOSITORIES, which are free for anyone to use. (Please take a moment to reflect on this. In fact, the invention of public repositories was one of the main reasons Linux became so important and so popular.)

Each package manager uses its own type of packages. For example, if you want to install Emacs on a Linux system that uses APT, you need an APT Emacs package; if you have a system that uses RPM, you need an RPM Emacs package. However, this isn’t something you need to worry about. All you need to do is tell your package manager what you want, and it will search the appropriate online repositories, find the package you want, download it, and install the software for you. Everything is automatic — and free.

If, for some reason, the program you want is not available as a package but you can find it in the form of an archive — a tarball for Unix or a zip file for Windows — you can download it yourself and do a manual installation. I’ll show you how to do this for Emacs in Section 3.3 (Linux) and Section 3.5 (Windows).

Finally, installing Emacs with OS X uses a completely different procedure, which I will show you in Section 3.4.

3.2 Section 3.2: Installing Emacs Using a Linux Package Manager

Each type of Linux uses a specific package management system (package manager). There are a variety of Linux package managers, the most widely used being APT and RPM. For reference, Figure 3-1 shows you the Linux package managers you are most likely to encounter. As you can see, APT is used by all Debian-based Linux distributions,2 and RPM is used by Fedora-based and SUSE-based distributions. Figure 3-2 shows you the package managers used by the three most popular BSD operating systems.

A385558_1_En_3_Fig1_HTML.gif
Figure 3-1. Linux Package Management Systems. To make software easy to share and download, most Unix systems use a package management system. The most widely used Linux package managers are shown in this table.
A385558_1_En_3_Fig2_HTML.gif
Figure 3-2. BSD Package Management Systems. This table shows the package managers you are most likely to encounter when you use a BSD-based version of Unix.

The package managers I have mentioned are all CLI-based programs. That is, you use them by typing commands. For completeness, I will mention that some types of Linux also have GUI-based programs. (For example, Ubuntu has a GUI-based package manager named Synaptic.) However, I won’t be discussing them here because the CLI-package managers are more widely used and, in my opinion, are more fun to use.

In this section, I will show you how to install Emacs using APT and RPM. If your operating system uses a different package manager, you can look it up online to see how it works, or you can use the information in Section 3.3 to install Emacs manually.

Installing Emacs using a package manager is easy. All you have to do is enter the appropriate command and everything will be done for you automatically.

3.2.1 Installing Emacs with APT

To install software with the APT package manager, you use the apt-get program. To install Emacs, the command to use is:

sudo apt-get -y install emacs                  

Let’s discuss this command, one piece at a time:

  • sudo runs the command as superuser, so you will have permission to install software on the system. You will need the superuser/administrator password to run this command. (We discussed the superuser in Section 2.3.)

  • apt-get is the program you want to run.

  • The -y option: During the installation process, apt-get will pause and ask your permission to proceed with various tasks. The -y option automatically answers "yes" to such prompts, so apt-get will not pause. If you so desire, you can leave out this option and respond to the prompts manually.

  • install tells apt-get that you want to install software.

  • emacs is the name of the package you want to install.

Once you have installed Emacs, you can test it by starting the program:

emacs                  

To quit Emacs, press <Ctrl-C> <Ctrl-X> .

To uninstall Emacs, use the following command:

sudo apt-get -y remove emacs                  

Using remove deletes the package but leaves its configuration files, which were used to help install the software.

By default, these files are left alone in case you have modified them. However, if you do not plan to reinstall the program or install a new version of the program, you may want to delete both the package and its configuration files. To do so, use:

sudo apt-get -y remove $$purge emacs                  

3.2.2 Installing Emacs with RPM

To install software with the RPM package manager, there are two programs you might use. The best choice is DNF. To install Emacs, the command to use is:

sudo dnf -y install emacs                  

To uninstall Emacs, use the following command:

sudo dnf -y erase                    3                    emacs                  

DNF is a replacement for an older program called YUM. DNF is better than YUM, so it should be your first choice.4 However, if your system uses RPM but it doesn’t have DNF, you can use YUM. The syntax is the same as DNF:

sudo yum -y install emacs                  
udo yum -y erase emacs

Once you have installed Emacs, you can test it by starting the program:

emacs                  

To quit Emacs, press <Ctrl-C> <Ctrl-X> .

3.3 Section 3.3: Installing Emacs Manually With Linux

The following instructions show you how to install GNU Emacs manually on a Debian-based Linux system (this includes the Ubuntu and Mint families). A manual installation involves downloading a tarball from the GNU Emacs archive, and then unpacking, compiling, and installing the program. Normally, you would use a package manager, which is a lot easier. However, in some cases, you will want to do a manual installation. Here is an example.

When I was working on this book, the most up-to-date version of Emacs was 24.5. At the time, the latest version of Emacs for which there was a package in the Debian repository was 24.4. (It can take a while for a package to be created when a new version is released.) I could use apt-get to install Emacs 24.4 but, for technical reasons, I wanted to test 24.5, so I had to install it manually.

Below I will show you the procedure I followed. Although the details (such as version numbers) will change as time passes, the general principles won’t, so you can modify the following commands to suit your needs.

When you read my annotated procedure for installing Emacs by hand, do take a moment to make sure you understand each step. At the end of the section, I will give you all the commands in a quick list, to make it easy for you to enter them one after another. So don’t do anything right now. Just read through my comments until you get to the list of commands at the end of the section.

1. Before you start, be sure to uninstall any existing Emacs programs that may already be on your system. For example, if you have previously installed Emacs using apt-get you can use the command:

sudo apt-get -y remove emacs                
  1. 2.  On Debian systems, the tools you need to build a program from source code are not installed by default. So before you can compile and install anything, you need to install these tools (compilers, libraries, and so on). They are in a package called build-essential. The command to use is:

    sudo apt-get install build-essential                        
IMPORTANT:

Be sure to type essential, not essentials.

  1. 3.  Make sure your system satisfies the build dependencies for Emacs version 24:

    sudo apt-get build-dep emacs24                        
IMPORTANT:

Be sure to specify only the major version number. Do not include the minor number. In our example, I used emacs24, not emacs24.5. If you include the minor number (24.5) it won’t work, and it will take a long time to figure out why.

Note

When you run the apt-get build-dep command for the first time, you may reach a point where the program pauses to ask you to specify the "Postfix Configuration". (Postfix is a mail server, a program that delivers email over a network. Configuring Postfix is important if you plan to send email from Emacs.)

You will see a text menu with several choices. Use the Tab key to move to the configuration type that best describes your system. Then press <Enter> to make your selection. If you are not sure what to do, select "No configuration".

  1. 3.  Change to your home directory and create a subdirectory to hold the installation files:

    cd & & mkdir emacs-24.5-install                    
  2. 4.  Change to the installation directory:

    cd emacs-24.5-install                        
  3. 5.  Download the tarball you need to install Emacs. First, use your Web browser to visit the GNU Emacs FTP server:

    http://ftp.gnu.org/gnu/emacs/                        

    Look for the appropriate tarball, and download it using wget (a program to retrieve content from Web servers):

    wget http://ftp.gnu.org/gnu/emacs/emacs-24.5.tar.gz                        

    The file will be downloaded into the current directory (in this case, emacs-24.5-install).

  4. 6.  Extract the installation files from the tarball.

    tar -xvzf emacs-24.5.tar.gz                        

    At this point, the Emacs source programs will be in a subdirectory with the name taken from the tarball: in our case, emacs-24.5.

  5. 7.  Change to the subdirectory that holds the installation files:

    cd emacs-24.5                        
  6. 8.  Configure the Emacs software:

    ./configure                        
  7. 9.  Build the Emacs software:

    make                        
  8. 10.  Install Emacs:

    sudo make install                        
  9. 11.  Test to see if Emacs is installed properly, by starting the program:

    emacs                        

To quit Emacs, press <Ctrl-C> <Ctrl-X> .

For reference, here are all the commands in an easy-to-read list. Remember, before you start, make sure that you have uninstalled any existing version of Emacs:

sudo apt-get -y remove emacs                

Also, visit the GNU Emacs FTP server and find the tarball you want:

http://ftp.gnu.org/gnu/emacs/                

In our example, it is emacs-24.5.tar.gz. In the commands below, change the version numbers appropriately.

Here are the commands you need to install Emacs manually on a Debian-based Linux system:

sudo apt-get install build-essential                
sudo apt-get build-dep emacs24
cd && mkdir emacs-24.5-install
cd emacs-24.5-install
wget http://ftp.gnu.org/gnu/emacs/emacs-24.5.tar.gz
tar -xvzf emacs-24.5.tar.gz
cd emacs-24.5
./configure
make
sudo make install

To see if Emacs is installed properly, enter:

emacs                

To quit Emacs, press <Ctrl-C> <Ctrl-X> .

3.4 Section 3.4: Installing Emacs With OS X

Installing Emacs with OS X is a multi-step process. First you modify your system settings to allow you to run a program downloaded from the Internet. Then you download and mount a disc image of the Emacs installation software. You then install Emacs, and create an icon for it in the Dock. Finally, you start Emacs to make sure it works.

3.4.1 1. ENABLE THE RUNNING OF PROGRAMS DOWNLOADED FROM THE INTERNET

Before you can install Emacs with OS X, you need to make sure your settings allow you to run programs downloaded from the Internet.

a. Open Finder, click "Applications", then double-click "System Preferences". The "System Preferences" will open.

b. Within "System Preferences", click "Security & Privacy". The "Security & Privacy" window will open.

At the bottom of the General Tab where it says "Allow apps downloaded from:" If "Anywhere" is selected, that is fine. Close the window.

If not, you need to change the setting to "Anywhere".

c.  Click the icon of a lock next to "Click the lock to make changes". You will be asked to type your password. Type the password you use to log in to your account, then click "Unlock".

d. At the bottom of the General Tab where it says "Allow apps downloaded from:", select "Anywhere".

e. If you see a warning message, read it and then click "Allow From Anywhere". If you see a window with a warning that this setting will change back after 30 days, click "Allow From Anywhere" to approve the change.

f. To finish, lock the setting by clicking the icon of the lock next to "Click the lock to prevent further changes".

g. Close the "Security & Privacy" window.

3.4.2 2. DOWNLOAD A DISK IMAGE OF THE INSTALLATION SOFTWARE

To install Emacs, you must download a DMG ("disk image") file. A DMG file holds the image of an optical disc, so you can think of it as a virtual disc. (A DMG file is the Mac version of an ISO file.)

The Web page to download a DMG file containing Emacs for OS X is:

http://www.emacsformacosx.com/                    5                  

Start your browser, visit this page, and download the DMG file. The file should end up in your Downloads folder. If you can’t find it there, check your desktop. Once you are sure the file is downloaded, you can close your browser.

3.4.3 3. MOUNT THE DMG FILE

When you MOUNT a disc image file, it emulates your putting a real disc into your CD or DVD device. If you have any experience using ISO files with Unix or Windows, you will see that mounting a DMG file on a Macintosh is like mounting an ISO file, only easier.

All you need to do is use Finder to open the Downloads folder. Then double-click on the DMG file and wait. Your disc image will be mounted automatically. As this happens, you will see a notice that the DMG file is being opened. Once the DMG file is mounted, you will see an icon for the program (in this case, an Emacs icon).

3.4.4 4. INSTALL EMACS

Drag the Emacs icon to your Applications folder. It is that easy.

3.4.5 5. CREATE A DOCK ICON

Use Finder to open the Applications folder. Find the Emacs icon, and drag it to the Dock for easy access. You can now close the Applications folder. (The Dock is like the Ubuntu Launcher or the Windows Taskbar.)

3.4.6 6. START EMACS TO MAKE SURE IT WORKS

Click the Emacs icon in the Dock to start the program. If your permissions have not been set up properly, you will see:

"Emacs" can't be opened because it was not downloaded from the Mac APP store                  

If so, simply follow the instructions in Step 1 above. Otherwise, the first time you run Emacs, you will see:

"Emacs" is an application downloaded from the Internet.                  
Are you sure you want to open it?

Click "Open" to start the program. If necessary, bring the focus to the Emacs window by clicking on it.

3.4.7 7. QUIT EMACS

To quit Emacs, press: <Control-X> <Control-C>. (Be sure to use <Control>, not <Command> .)

3.4.8 8. “EJECT” THE DISC IMAGE

Now that you are finished with the virtual disc, you can "eject" it. Look on your Desktop for a white and gray icon with the name Emacs. This represents the mounted DMG file.

Click on the icon. Then press <Command-E>, which will instantly "eject" the virtual disc, at which time the icon for the mounted DMG file will disappear.

3.4.9 9. DELETE THE DMG FILE

Use Finder to open the Downloads folder. Drag the DMG file to the Trash folder. If you want, empty the Trash. Close Finder.

3.5 Uninstalling Emacs

If you ever want to uninstall Emacs, the process is easy: just drag the Emacs icon from the Applications folder to the Trash.

To remove the Emacs icon from the Dock, right-click on the Emacs icon and select Options, and then "Remove from Dock".

Note

When you use a mouse, there are two basic ways to click: a regular "click" and a "right-click". On a Macintosh, these two types of clicks are referred to formally as a PRIMARY CLICK (click) and a SECONDARY CLICK (right-click). When I instructed you (above) to right-click on the Emacs icon, I was referring to a secondary click.

With a Macintosh two-button mouse, one button sends the primary click; the other sends a secondary click. If you have a one-button mouse, to create a secondary click (a right-click), hold down the Control key as you click.

With a Macintosh touchpad, one of the following should work:

  • Touch the touchpad with two fingers.

  • Touch the bottom right corner of the touchpad.

  • Touch the bottom left corner of the touchpad.

It is a good idea to set the primary and secondary clicks on your system to suit your preferences. To do so, use Finder to open the Applications folder. Then open "System Preferences", and choose either Mouse or Trackpad.

3.6 Section 3.5: Installing Emacs With Microsoft Windows

To install Emacs with Microsoft Windows you don’t run a setup program, as is usually the case with Windows software. Instead, you download the appropriate archive and then extract its contents. You can then pin the Emacs program to your Taskbar or create an icon for it.

Before you start, you need to choose a directory into which you will install Emacs. If you don’t have a master plan for your directory structure, I suggest you use C:Emacs, which is what I will use in the examples below.

Note

During this procedure, you will need to use the Windows file manager. In Windows 7, the file manager is Windows Explorer. In Windows 8 and Windows 10, it is File Explorer.

3.6.1 1. CREATE AN EMACS DIRECTORY

Use the Windows file manager to create the directory C:Emacs.

3.6.2 2. DOWNLOAD THE EMACS ARCHIVE

Use your Web browser to visit the GNU Emacs FTP server where the Windows archives are stored:

http://ftp.gnu.org/gnu/emacs/windows/                  

Look for the version of Emacs you want to install. (I suggest the latest version.) In our example, I will use:

emacs-24.5-bin-i686-mingw32.zip                  

Click on this link to download the file to your computer. Be sure to save the file to the C:Emacs directory (not to your Downloads directory).

Note

When you download an archive (or a setup program) for Microsoft Windows, it will contain binary files, all ready to run. This is convenient, but it also makes it easier to infect your computer with malware, such as viruses or trojans. With binary files, there is no way of knowing what’s inside the installation package. With source files, anyone can look inside the programs, so the programs are open to the world.

For this reason, before you install any Windows program, it behooves you to use an up-to-date antivirus program to check the installation file for malware.

3.6.3 3. EXTRACT THE CONTENTS OF THE ARCHIVE

Use the Windows file manager to navigate to C:Emacs. Look for the archive (zip file) you just downloaded. To extract its contents, right-click on the file name and choose "Extract All".

You will see a dialogue asking you to select the directory to hold the contents of the archive. Before you proceed, make sure that there is a checkmark next to "Show extracted files when complete".

You will see a suggestion to create a directory with the same name as the first part of the zip file. In our example, it is:

C:Emacsemacs-24.5-bin-i686-mingw32                  

Unless you have a good reason to use another directory, accept the default choice. To process the archive, click Extract.

Once the extraction process is finished, you will see a file manager window showing you the contents of the destination directory. Specifically, you should see four directories: bin, libexec, share and var. Within these directories are some subdirectories and a large number of files.

At this point, your Emacs installation is complete.

Note

In a moment, you will be running Emacs. The first time you run the program, you may see a warning:

The publisher could not be verified.                    
Are you sure you want to run this software?

As long as you downloaded the Emacs archive from the official GNU Emacs FTP site, it is safe to uncheck the box next to "Always ask before opening this file". That way, you won’t be bothered every time you want to run the program.

3.6.4 3. START EMACS TO MAKE SURE IT WORKS

Within the file manager, change to the bin directory. In our example:

C:Emacsemacs-24.5-bin-i686-mingw32in                  

You will see a number of executable programs (.exe files). To start Emacs, run the program runemacs.exe. Once Emacs is running, you can quit it by pressing <Ctrl-X> <Ctrl-C> .

3.6.5 4. MAKE EMACS EASY TO RUN

To make Emacs easy to run whenever you want, you can pin it to the Taskbar. To do so, use the file manager to navigate to the Emacs bin directory. Right-click on runemacs.exe and select "Pin to Taskbar".

To create an Emacs icon, run the program addpm.exe. (It’s in the same directory.)

3.6.6 5. CLEAN UP

You can now delete the Emacs archive file. In our example, it is:

emacs-24.5-bin-i686-mingw32.zip                  

Footnotes

1 See Personal Note #27, "Comparing Unix Packages to Commercial Apps" (Appendix A).

2 Debian Linux was created in 1993 and is still actively developed. Over the years, Debian has spawned a large number of derivative Linux distributions, including the popular Ubuntu and Mint families.

3 You can use either erase or delete, but delete is deprecated.

4 For example, DNF is much better at handling dependencies.

5 If this Web site doesn’t work, search online for: installing emacs "os x".

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.83.240