CentOSRHEL Based

How To Install Emacs on CentOS Stream 10

Install Emacs on CentOS Stream 10

Emacs stands as one of the most powerful and versatile text editors in the Linux ecosystem, offering capabilities that extend far beyond simple text editing. For CentOS Stream 10 users, installing Emacs provides access to an incredibly customizable environment that can transform your coding, writing, and system administration workflows. This comprehensive guide walks you through multiple installation methods, configuration options, and troubleshooting steps to help you get Emacs up and running on CentOS Stream 10 effectively.

Understanding Emacs and CentOS Stream 10

What is Emacs?

Emacs (Editor MACroS) is much more than a text editor—it’s a complete computing environment that has evolved over decades. Created by Richard Stallman in 1976, Emacs has grown into a highly extensible system that can be customized to handle virtually any text-processing task. Its core is written in C, but its extensive functionality comes from Emacs Lisp, a dialect of the Lisp programming language that allows users to modify and extend the editor.

Key features that set Emacs apart include:

  • Extensive customization capabilities through Emacs Lisp
  • Built-in support for dozens of programming languages
  • Integrated development environment features
  • Version control integration
  • Email and news reader functionality
  • Calendar and organizer capabilities
  • Text-based file manager
  • Games and entertainment options

For developers, system administrators, and power users, Emacs offers an environment where tasks that would normally require multiple applications can be performed within a single, integrated interface.

CentOS Stream 10 Overview

CentOS Stream 10 represents the latest evolution in the CentOS project, functioning as a rolling-release distribution that bridges the gap between Fedora and Red Hat Enterprise Linux (RHEL). Unlike the traditional CentOS that followed RHEL releases, CentOS Stream operates as a development platform that flows slightly ahead of RHEL, providing a preview of upcoming features.

CentOS Stream 10 includes several improvements over previous versions:

  • Enhanced system management tools
  • Updated security features
  • Improved container support
  • More recent kernel versions
  • Better hardware compatibility

This distribution is particularly suited for organizations that want to test their applications against future RHEL releases and for developers who need a stable yet forward-looking platform.

Benefits of Using Emacs on CentOS Stream 10

The combination of Emacs and CentOS Stream 10 offers several advantages. CentOS Stream’s stability and enterprise focus provide a reliable platform for Emacs to operate on. Meanwhile, Emacs enhances productivity for CentOS users through its extensive customization options and integrated tools.

For system administrators managing CentOS servers, Emacs provides powerful text processing capabilities for configuration file editing and script development. Developers benefit from Emacs’ programming language support and integrated development tools, all running on a platform designed for production environments.

Prerequisites for Installation

System Requirements

Before installing Emacs on CentOS Stream 10, ensure your system meets these minimum requirements:

  • 1 GHz processor (2 GHz or faster recommended)
  • 1 GB RAM (2 GB recommended for comfortable usage)
  • 500 MB free disk space for installation (more for source builds)
  • Internet connection for downloading packages

While Emacs can run on minimal hardware, a more powerful system will provide a smoother experience, especially when using multiple plugins or processing large files.

Required Access Levels

Installing Emacs requires administrative privileges on your CentOS Stream 10 system:

  • Root access or sudo privileges are necessary for system-wide installation
  • Standard user privileges are sufficient for using Emacs once installed

When following this guide, commands requiring elevated privileges will be prefaced with sudo. Ensure your user account has sudo capabilities before proceeding.

Preparing Your System

Before installation, take these preparatory steps:

1. Update your system to ensure all packages are current:

sudo dnf update -y

2. If you have any existing Emacs installation or configuration, back it up:

# Back up configuration if it exists
if [ -f ~/.emacs ]; then cp ~/.emacs ~/.emacs.backup; fi
if [ -d ~/.emacs.d ]; then cp -r ~/.emacs.d ~/.emacs.d.backup; fi

3. Install development tools that might be needed:

sudo dnf groupinstall "Development Tools" -y

With these preparations complete, you’re ready to install Emacs using one of several methods.

Method 1: Installing Emacs using DNF

Understanding DNF Package Manager

DNF (Dandified Yum) is the default package manager for CentOS Stream 10. It handles package installation, updates, and dependencies automatically, making it the easiest method for installing Emacs.

DNF maintains a database of available packages and their dependencies, simplifying the installation process by resolving and installing required components automatically. This approach ensures system stability and compatibility with other installed software.

Step 1: Updating the System

Before installing any new software, always update your system to ensure you have the latest packages and security patches:

sudo dnf update -y

This command refreshes the package database and updates all installed packages to their latest versions. The -y flag automatically confirms all update prompts, streamlining the process.

Wait for the update process to complete before proceeding. This step is crucial as it prevents potential conflicts with outdated packages during the Emacs installation.

Step 2: Installing Emacs

To install the standard Emacs package on CentOS Stream 10, run:

sudo dnf install emacs -y

This command installs the default Emacs package along with all necessary dependencies. CentOS Stream 10 typically provides Emacs 28 or newer in its repositories.

If you prefer a lighter version without graphical capabilities (useful for server environments), you can install the terminal-only version:

sudo dnf install emacs-nox -y

To verify your installation was successful, check the installed version:

emacs --version

This should display the Emacs version information, confirming that the installation was successful.

Step 3: Post-Installation Configuration

After installation, you can launch Emacs with:

emacs

For the graphical version, or:

emacs -nw

For the terminal version. The first launch may take slightly longer as Emacs creates default configuration files.

To ensure Emacs is accessible from your desktop environment, you might need to refresh your application menu:

# For GNOME desktop environment
touch ~/.config/gnome-menus/applications.menu

Troubleshooting DNF Installation

If you encounter issues during installation, try these solutions:

  • Repository problems: If you see errors about repositories being unavailable, try:
    sudo dnf clean all
    sudo dnf update
  • Dependency conflicts: If DNF reports dependency conflicts, you might need to remove conflicting packages or try an alternative installation method.
  • Insufficient disk space: If the installation fails due to disk space issues, clear your DNF cache:
    sudo dnf clean all

Method 2: Building Emacs from Source

Why Build from Source?

Compiling Emacs from source code offers several advantages:

  • Access to the latest version with newest features
  • Ability to customize compile-time options
  • Better performance through optimization for your specific hardware
  • Inclusion or exclusion of specific features based on your needs

Building from source is recommended for users who need the cutting-edge features not yet available in the package repositories or who require specific customizations not available in pre-built packages.

Step 1: Installing Build Dependencies

Before compiling Emacs, you need to install the necessary development libraries and tools:

sudo dnf groupinstall "Development Tools" -y
sudo dnf install gtk3-devel gnutls-devel libxml2-devel jansson-devel GConf2-devel Xaw3d-devel libXpm-devel giflib-devel libjpeg-turbo-devel libpng-devel libtiff-devel ncurses-devel librsvg2-devel -y

These packages provide the libraries necessary for a fully-featured Emacs build. For a more minimal build without GUI support, you could omit some of the graphical libraries.

To ensure all dependencies are properly installed, check if there were any errors in the installation process before proceeding.

Step 2: Downloading the Source Code

Next, download the latest Emacs source code from the GNU project’s servers:

cd /tmp
wget https://ftp.gnu.org/gnu/emacs/emacs-29.1.tar.xz

Replace “29.1” with the latest version available at the time of installation. Verify the download integrity using:

wget https://ftp.gnu.org/gnu/emacs/emacs-29.1.tar.xz.sig
gpg --verify emacs-29.1.tar.xz.sig

You might need to import the GNU Emacs maintainer’s key if it’s not already in your keyring.

Extract the source code:

tar -xf emacs-29.1.tar.xz
cd emacs-29.1

Step 3: Configuring the Build

Run the configure script to prepare for compilation:

./configure --with-x-toolkit=gtk3 --with-modules

This configuration includes GTK3 toolkit support and dynamic module loading. You can customize this step with various options:

  • --prefix=/usr/local – Sets the installation directory
  • --without-x – Builds a terminal-only version
  • --with-cairo – Enables Cairo drawing support for improved graphics
  • --with-imagemagick – Adds ImageMagick support for image processing

For a complete list of options, run:

./configure --help

The configuration process will check your system for all required dependencies and create a build plan tailored to your environment.

Step 4: Compiling and Installing

Once configuration is complete, compile Emacs:

make -j$(nproc)

The -j$(nproc) option tells make to use all available CPU cores, significantly speeding up the build process. On a typical modern system, compilation takes 5-15 minutes.

After successful compilation, install Emacs:

sudo make install

This command copies the compiled binaries and support files to their appropriate locations, typically under /usr/local/.

Verify the installation:

/usr/local/bin/emacs --version

If the installation was successful, this command will show the version information for your newly compiled Emacs.

Advantages and Disadvantages

Building from source provides the latest features and optimizations but requires more technical knowledge and time. This method is best for users who need specific features not available in pre-packaged versions or who want maximum performance from their text editor.

Method 3: Installing Emacs using Snap

Introduction to Snap Packages

Snap is a containerized software package management system developed by Canonical, the company behind Ubuntu. Unlike traditional package managers, Snap packages bundle applications with their dependencies, ensuring they run consistently across different Linux distributions.

Snaps offer several benefits:

  • Self-contained packages with all necessary dependencies
  • Automatic updates
  • Isolation from the rest of the system for improved security
  • Consistent behavior across different Linux distributions

For Emacs, Snap provides a way to install the latest version without dealing with potential dependency issues.

Step 1: Installing Snap on CentOS Stream 10

CentOS Stream 10 doesn’t come with Snap pre-installed, so you’ll need to add it first:

sudo dnf install epel-release -y
sudo dnf install snapd -y
sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap  # Create classic snap link

After installation, it’s recommended to reboot your system or wait a few minutes to ensure Snap’s services are fully initialized:

sudo systemctl restart snapd.service

Step 2: Installing Emacs via Snap

Once Snap is set up, installing Emacs is straightforward:

sudo snap install emacs --classic

The --classic flag gives the Emacs snap access to your system outside the typical snap confinement model, which is necessary for most Emacs functionality.

Verify the installation:

snap list emacs

This should show the installed Emacs version. You can now launch Emacs using:

snap run emacs

Or simply:

emacs

If your PATH includes the Snap binary directory.

Advantages and Limitations of Snap Installation

Snap installation offers several benefits:

  • Easy access to the latest Emacs versions
  • Automatic updates when new versions are released
  • Isolation from system libraries, preventing conflicts

However, there are some limitations:

  • Higher disk usage due to bundled dependencies
  • Slightly slower startup time compared to native packages
  • Potential permission issues with accessing certain system resources
  • Some integration features may work differently than with native packages

Snap installation is ideal for users who want the latest Emacs version with minimal configuration and are willing to trade some performance for convenience.

Basic Configuration of Emacs

Understanding Configuration Files

Emacs uses several configuration files to customize its behavior:

  • ~/.emacs – Traditional user configuration file
  • ~/.emacs.d/init.el – Modern configuration file (preferred)
  • ~/.emacs.d/ – Directory for additional configuration files and packages

When Emacs starts, it looks for these files in order. Most modern Emacs setups use the ~/.emacs.d/init.el approach, which allows for better organization of configuration code.

To create a basic configuration file:

mkdir -p ~/.emacs.d
touch ~/.emacs.d/init.el

You can then edit this file with Emacs itself:

emacs ~/.emacs.d/init.el

Essential Configurations for Beginners

Here are some basic configurations to improve your Emacs experience:

;; Disable the splash screen
(setq inhibit-startup-message t)

;; Display line numbers
(global-display-line-numbers-mode t)

;; Enable syntax highlighting
(global-font-lock-mode t)

;; Show matching parentheses
(show-paren-mode 1)

;; Make indentation commands use space only
(setq-default indent-tabs-mode nil)

;; Set the default tab width
(setq-default tab-width 4)

;; Enable the built-in package manager
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)

These settings provide a more comfortable editing experience by enabling features that most modern editors have by default.

Creating a Custom Configuration

To create a more personalized configuration, follow these steps:

  1. Identify features you need in your workflow
  2. Search for appropriate Emacs packages or built-in modes
  3. Add configuration code to your init.el file
  4. Test each change incrementally to isolate any issues

Here’s an example of extending your configuration with a popular theme:

;; Install and load a theme
(unless (package-installed-p 'zenburn-theme)
  (package-refresh-contents)
  (package-install 'zenburn-theme))
(load-theme 'zenburn t)

Remember to back up your configuration regularly:

cp -r ~/.emacs.d ~/.emacs.d.backup-$(date +%Y%m%d)

Popular Emacs Distributions and Packages

Spacemacs Overview and Installation

Spacemacs is a community-driven Emacs distribution that combines the editing style of Vim with the extensibility of Emacs. It provides a curated set of packages and configurations that work well together.

To install Spacemacs on CentOS Stream 10:

# Backup existing configuration if any
[ -d ~/.emacs.d ] && mv ~/.emacs.d ~/.emacs.d.bak
[ -f ~/.emacs ] && mv ~/.emacs ~/.emacs.bak

# Clone Spacemacs repository
git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d

Launch Emacs to complete the Spacemacs installation process. You’ll be prompted to choose an editing style:

  • Evil (Vim keybindings)
  • Holy (Traditional Emacs keybindings)
  • Hybrid (combination of both)

Spacemacs includes many pre-configured layers for different programming languages and tools, making it an excellent choice for developers new to Emacs.

Doom Emacs Introduction

Doom Emacs is a configuration framework for Emacs that emphasizes speed and minimalism while providing modern features. It’s designed to be faster and more streamlined than other Emacs distributions.

To install Doom Emacs:

# Backup existing configuration
[ -d ~/.emacs.d ] && mv ~/.emacs.d ~/.emacs.d.bak

# Clone Doom Emacs repository
git clone --depth 1 https://github.com/hlissner/doom-emacs ~/.emacs.d

# Install Doom Emacs
~/.emacs.d/bin/doom install

After installation, you can use the doom command to manage your configuration:

~/.emacs.d/bin/doom sync  # Synchronize your config
~/.emacs.d/bin/doom doctor  # Check for potential issues

Doom Emacs is particularly well-suited for users who want a highly optimized Emacs experience without sacrificing modern features.

Essential Packages for Development

Whether you use standard Emacs or a distribution, these packages can enhance your development workflow:

  • Magit: The best Git interface available for any editor
    (use-package magit
      :ensure t
      :bind ("C-x g" . magit-status))
  • LSP Mode: Language Server Protocol support for dozens of programming languages
    (use-package lsp-mode
      :ensure t
      :commands lsp
      :hook ((prog-mode . lsp)))
  • Company: In-buffer completion system
    (use-package company
      :ensure t
      :hook (after-init . global-company-mode))
  • Projectile: Project interaction library
    (use-package projectile
      :ensure t
      :config
      (projectile-mode +1))

These packages provide modern IDE-like features within Emacs, making it a powerful development environment.

Getting Started with Emacs

Basic Commands and Navigation

Once Emacs is installed, familiarize yourself with these essential commands:

  • C-x C-f – Find file (open)
  • C-x C-s – Save file
  • C-x C-c – Exit Emacs
  • C-g – Cancel current command
  • C-x b – Switch buffer
  • C-x k – Kill (close) buffer

For navigation:

  • C-p / C-n – Previous/next line
  • C-b / C-f – Backward/forward character
  • M-b / M-f – Backward/forward word
  • C-a / C-e – Beginning/end of line
  • M-< / M-> – Beginning/end of buffer

In Emacs notation, C- means hold the Ctrl key, and M- means hold the Alt (Meta) key.

Text Editing Fundamentals

Emacs provides powerful text manipulation commands:

  • C-space – Set mark (start selection)
  • C-w – Cut selected text
  • M-w – Copy selected text
  • C-y – Paste (yank) text
  • C-k – Kill (cut) to end of line
  • C-/ – Undo
  • C-s / C-r – Search forward/backward
  • M-% – Search and replace

For working with multiple files:

  • C-x 2 – Split window horizontally
  • C-x 3 – Split window vertically
  • C-x o – Move to other window
  • C-x 0 – Close current window

Productivity Tips for New Users

To become productive in Emacs quickly:

  • Use the built-in tutorial: Start Emacs and press C-h t
  • Learn incremental search (C-s) for navigating files quickly
  • Set up a minimal configuration first, adding features as needed
  • Use M-x describe-function and M-x describe-key to learn about commands
  • Try the built-in viper-mode if you’re used to Vim keybindings
  • Consider using a distribution like Spacemacs or Doom Emacs for a better initial experience

Troubleshooting Common Issues

Installation Problems

If you encounter issues during installation:

  • Missing dependencies: If the DNF method shows missing dependencies, install them manually:
    sudo dnf install gnutls-devel libxml2-devel jansson-devel
  • Permission denied errors: Ensure you’re using sudo or have proper permissions:
    # Check if you have sudo access
    sudo -l
  • Repository connectivity issues: Try changing to a different mirror:
    sudo dnf config-manager --setopt=fastestmirror=true

Runtime Errors

For problems when running Emacs:

  • Display issues: If the GUI version shows rendering problems, try the terminal version:
    emacs -nw
  • Slow startup: Check your configuration for performance issues:
    emacs --debug-init
  • Package loading errors: Refresh your package archives:
    M-x package-refresh-contents

Configuration Troubleshooting

For configuration problems:

  • Reset to defaults: Temporarily run Emacs without your configuration:
    emacs -q
  • Identify problematic code: Use bisection to find issues in your config:
    # Comment out half your init.el, restart Emacs, and repeat until you find the problem
  • Package conflicts: If packages conflict, try updating or removing them:
    M-x package-list-packages
    # Press 'U' then 'x' to update all packages

Congratulations! You have successfully installed Emacs. Thanks for using this tutorial to install the Emacs text editor on CentOS Stream 10. For additional help or useful information, we recommend you check the official Emacs website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button