For those aiming to install GNU Emacs on Ubuntu 22.04 Jammy Jellyfish or its older stable release of Ubuntu 20.04 Focal Fossa, you’re about to embark on a journey with one of the most powerful text editors available. GNU Emacs, more than just a text editor, is an extensible, customizable, and free/libre text editor. With a heritage stemming from the GNU project, its open-source foundation ensures it remains at the forefront of text editing tools, adapting to modern computing needs.
Key Features of GNU Emacs:
- Extensibility: At its core, Emacs is built on the Emacs Lisp programming language, allowing users to tailor and expand almost every facet of the editor.
- Integration: More than a standalone tool, Emacs seamlessly integrates with various software, serving multiple roles like a shell, version control system, or web browser.
- Versatility: Capable of managing numerous file types, Emacs is adept at handling plain text, programming languages, markup languages, and even binary files.
- Language Support: With built-in modes for countless programming languages, Emacs offers syntax highlighting, indentation, and other language-specific features right out of the box.
- Keyboard-Centric: Known for its keyboard-driven workflow, Emacs allows users to execute most actions without the need to touch the mouse, promoting efficiency.
- Community and Documentation: Backed by an extensive community, Emacs benefits from a continuous influx of packages, themes, and extensions. Its detailed documentation, inclusive of the in-built Emacs tutorial, aids newcomers in their Emacs journey.
What Sets GNU Emacs Apart?
- Self-Documenting: Emacs offers a unique self-documenting feature. Users can utilize ‘describe’ commands to understand functions, arguments, and implementations.
- Macros: With its robust macro capabilities, users can define command sequences, bind them to keys, and automate repetitive tasks.
- Emacs Lisp: Being an interpreter for Emacs Lisp, a Lisp programming dialect, Emacs offers boundless customization and extension possibilities.
- Org-mode: The Org-mode in Emacs is a comprehensive tool for note-taking, TODO lists, and project planning, positioning Emacs as a holistic productivity tool.
While mastering GNU Emacs demands dedication, its unmatched flexibility and power make it indispensable for programmers, system administrators, and advanced users.
Our upcoming guide will detail the steps to install GNU Emacs on Ubuntu 22.04 Jammy Jellyfish and Ubuntu 20.04 Focal Fossa. These methods also apply to other Ubuntu versions that haven’t reached their end-of-life. We’ll outline three primary installation approaches: APT, Snap, and Flatpak via the Flathub repository.
Install GNU Emacs on Ubuntu 22.04 or 20.04 via APT
Step 1: Refreshing the Ubuntu System Before GNU Emacs Installation
Before we venture into the installation of GNU Emacs, it’s imperative that we first refresh the packages on our Ubuntu system. This way, we ensure that our system is up-to-date, avoiding potential conflicts or issues arising from outdated packages. To update your system, execute the commands below in your terminal:
sudo apt update
sudo apt upgrade
The sudo apt update command fetches the list of available updates from the repositories, while the sudo apt upgrade upgrades your system’s current packages to their latest versions.
Step 2: Install GNU Emacs on Ubuntu 22.04 or 20.04 VIA APT Command
There are two primary methods to install GNU Emacs using APT:
Method 1: Installing GNU Emacs Directly from Ubuntu’s Repository
This method is the most straightforward and often recommended approach, especially for LTS (Long Term Support) distributions. While the version you’ll get may not be the latest, it’s guaranteed to be stable and compatible with your system, hence less likely to cause disruptions.
To install the default version of GNU Emacs from Ubuntu’s repositories, enter the following command in your terminal:
sudo apt install emacs
Method 2: Installing GNU Emacs via PPA on Ubuntu
The second method of installing Emacs using APT involves leveraging a PPA (Personal Package Archive). For this guide, we’ll be using the PPA by Kevin Kelley. The beauty of this PPA is its versatility — it provides builds for Emacs 28, 27, 26, and 25. This is especially useful if you’re looking for a specific version of Emacs.
The first step to using this method is to import the PPA to your system with the command below:
sudo add-apt-repository ppa:kelleyk/emacs -y
Once the PPA has been added, it’s crucial to refresh your system again using sudo apt update
. This allows your system to recognize the newly added PPA and incorporate it into its package sources:
sudo apt update
To view the versions of Emacs available in this PPA, you can use the following:
sudo apt-cache show emacs* | grep "Version"
For most users, the latest version, Emacs version 28, will be the preferred choice when writing this guide. To install this version, run the following:
sudo apt install emacs28
It’s worth noting that if you’re working in a headless environment like the Ubuntu server, you’ll only be able to install the terminal variation of Emacs. You can do this using the following command:
sudo apt install emacs28-nox
The ‘nox’ in emacs28-nox stands for ‘no X,’ referring to the absence of a graphical interface. Hence, this version of Emacs will operate solely in your terminal, making it suitable for server environments.
Install GNU Emacs on Ubuntu 22.04 or 20.04 via Snap
The Snap package manager offers an alternative method for Ubuntu users to install GNU Emacs. The Snap version of Emacs is typically updated promptly as new versions become available. If you haven’t removed Snap from your system, you can easily install and run GNU Emacs via this route.
Step 1: Re-installing Snap, If Necessary
Snap is generally pre-installed on most modern Ubuntu distributions. However, if for any reason you’ve removed it from your system and wish to re-install it, the following command comes in handy:
sudo apt install snapd
The snapd
package is the background service that enables Snap applications to function on your system. By executing the command above, you restore Snap capabilities to your Ubuntu system, thereby paving the way for installing Emacs via Snap.
Step 2: Install GNU Emacs on Ubuntu 22.04 or 20.04 via Snap
Once you’ve confirmed the presence of snapd on your system, the path to installing Emacs becomes clear. For most Ubuntu users, a single command line suffices to get Emacs up and running:
sudo snap install emacs --classic
In this command, the –classic switch is worth noting. Like some other applications, GNU Emacs requires full access to the system, as it does more than edit text. The –classic confinement in Snap provides the same level of access to the system as traditional packages, allowing Emacs to function at its total capacity.
Install GNU Emacs on Ubuntu 22.04 or 20.04 via Flatpak and Flathub
This section introduces an alternative installation method for GNU Emacs via the Flatpak package manager. Flatpak provides a sandbox environment where users can run applications in isolation from the rest of the system, which brings about advantages like enhanced security, improved compatibility, and easy application distribution.
Step 1: Enable Flathub for GNU Emacs on Ubuntu
Before you install GNU Emacs through Flatpak, you must first enable the Flathub repository. Flathub is a primary source of Flatpak applications. To add the Flathub repository to your Flatpak configuration, use the following command:
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
This command lets your system access a vast library of applications, including GNU Emacs, distributed through Flathub.
Step 2: Install GNU Emacs on Ubuntu 22.04 or 20.04 via Flatpak Command
With the Flathub repository enabled, you can now install GNU Emacs. The flatpak install
command facilitates this:
flatpak install flathub org.gnu.emacs -y
You’ll install the latest GNU Emacs version from the Flathub repository by executing the command above.
If your system doesn’t have Flatpak installed, refer to our guide on “How to Install Flatpak on Ubuntu” for detailed instructions on installing the most recent supported version of Flatpak.
Flatpak ensures a secure, isolated environment where GNU Emacs runs smoothly without interfering with other system processes. It’s a handy alternative to traditional package managers like APT, especially when you’re keen on keeping up with the latest updates of GNU Emacs directly from the upstream developers.
Launching GNU Emacs (GUI or Terminal) on Ubuntu 22.04 or 20.04
Once you have successfully installed GNU Emacs on your system, you might wonder how to start this powerful text editor. Here, we’ll discuss multiple methods to launch GNU Emacs, catering to different installation paths and user preferences.
Launching GNU Emacs for Desktop Users on Ubuntu
Desktop users who’ve installed GNU Emacs via APT or other standard installation methods can launch the application by running the following command in their terminal:
emacs
This command fires up the GUI version of GNU Emacs, providing a user-friendly interface.
Launching GNU Emacs in a Headless Environment on Ubuntu
For Ubuntu server users or those operating in a headless environment, GNU Emacs can be launched using the following command:
emacs-nox
This version of Emacs runs in your terminal without requiring a graphical user interface. It is convenient for server environments.
Launching GNU Emacs for Snapcraft Installations on Ubuntu
Users who’ve opted for the Snapcraft method of installation can launch GNU Emacs using the following command:
snap run emacs
The ‘snap run’ command ensures that the correct version of GNU Emacs (installed via Snap) is invoked.
Launching GNU Emacs for Flatpak Users on Ubuntu
If you’ve installed GNU Emacs using Flatpak, you’ll need to launch it with a slightly different command:
flatpak run org.gnu.emacs
This command instructs Flatpak to run the version of GNU Emacs available in its sandboxed environment.
Launching GNU Emacs via Application Icon on Ubuntu
Most desktop users might prefer to launch GNU Emacs via its application icon. This can be accessed through the following path:
Activities > Show Applications > Emacs
Tips on Getting Started with Emacs on Ubuntu 22.04 or 20.04
With GNU Emacs now installed, we will now share a few recommendations for getting started with GNU Emacs for those unfamiliar with Emacs. These tips are just a basic stepping stone. For further details, investigate the official documentation.
Basic Emacs Commands with GNU Emacs on Ubuntu
Getting comfortable with some basic commands can significantly enhance your experience when starting with Emacs. A few commonly used ones include:
Ctrl-x Ctrl-s # Save the current file
Ctrl-x Ctrl-w # Save the current file with a different name
Ctrl-x Ctrl-f # Open a file
Ctrl-x k # Close current file
Ctrl-g # Cancel a command
Ctrl-x u # Undo
Don’t worry about memorizing all commands at once; it will come naturally with regular usage.
Navigating the Emacs Interface with GNU Emacs on Ubuntu
Emacs has a unique interface with various windows (termed “frames” in Emacs language) and panes. Some quick tips for navigation are:
- Switching between frames: Use the command
Ctrl-x o
to navigate between different frames. - Splitting Windows: You can split your Emacs window into multiple panes using the command
Ctrl-x 2
(split horizontally) andCtrl-x 3
(split vertically). - Closing Windows: To close a split window, use
Ctrl-x 0
. To close all other windows except the active one, useCtrl-x 1
.
Customizing GNU Emacs with GNU Emacs on Ubuntu
One of the strengths of Emacs is its high degree of customization. All settings in Emacs are stored in a configuration file known as the .emacs
or init.el
file located in your home directory. Here are a couple of suggestions to get you started:
- Setting the Theme: You can set the color theme by adding the following to your
.emacs
orinit.el
file:
(load-theme 'theme-name t)
Replace 'theme-name'
with the name of your preferred theme.
- Adding Line Numbers: To display line numbers in your text files, add the following to your
.emacs
orinit.el
file:
(global-display-line-numbers-mode)
Leveraging Emacs’ Extensive Documentation with GNU Emacs on Ubuntu
Emacs provides comprehensive built-in documentation. Access it by pressing Ctrl-h, followed by a command. For instance, Ctrl-h t launches the Emacs tutorial, while Ctrl-h r opens the Emacs manual.
Additional Commands with GNU Emacs on Ubuntu 22.04 or 20.04
Update GNU Emacs on Ubuntu 22.04 or 20.04
To maintain GNU Emacs’ optimal functionality and security, it is crucial to ensure that your software is kept up-to-date. Depending on your initial installation method, different commands will apply.
APT Update Command for GNU Emacs on Ubuntu
Emacs installed via the APT package manager can be updated by running the following command:
sudo apt upgrade && sudo apt upgrade
This command first updates the list of available packages and then upgrades all outdated packages on your system, including Emacs.
Flatpak Update Command for GNU Emacs on Ubuntu
If you installed Emacs using Flatpak, the following command will keep your application updated:
flatpak update
Flatpak handles updates differently than traditional package managers, checking for updates for all installed applications and runtimes.
Snap Update Command for GNU Emacs on Ubuntu
Snap users can update all installed snaps, including Emacs, using the snap refresh
command.
sudo snap refresh emacs
Remove GNU Emacs from Ubuntu 22.04 or 20.04
There might be situations where you may need to uninstall Emacs from your Ubuntu system. The removal process varies depending on the installation method you initially used.
APT Remove Command for GNU Emacs on Ubuntu
To remove an APT-installed version of Emacs, use the following command:
sudo apt remove emacs{version}
In addition, you may want to remove the PPA from your system if you are not planning on using it again:
sudo add-apt-repository --remove ppa:kelleyk/emacs -y
Flatpak Remove Command for GNU Emacs on Ubuntu
To uninstall GNU Emacs installed via Flatpak along with its data, use the following command:
flatpak uninstall --delete-data org.gnu.emacs
Snap Remove Command for GNU Emacs on Ubuntu
If you have installed Emacs as a Snap package, use the following command to remove it:
snap remove emacs
Closing Thoughts
In this guide, we’ve delved into installing, launching, managing, and getting started with GNU Emacs on the Ubuntu Linux distribution. Whether you install Emacs via the APT, Flatpak, or Snap package manager, this guide provides step-by-step instructions to navigate each method efficiently. Moreover, we discussed updating or removing Emacs depending on your specific needs. Learning to manage your Emacs installation is a crucial step in maintaining a secure and efficient coding environment.