Skip to content

Sed Environment

This chapter describes how to ensure sed is available on your system. sed (Stream EDitor) is a standard utility on virtually all Unix-like operating systems, including GNU/Linux and macOS.

Typically, sed is pre-installed. You can verify its presence by checking its version:

$ sed --version

If sed is installed, you will see output similar to this (the version number and copyright year will vary):

sed (GNU sed) 4.8
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Jay Fenlason, Tom Lord, Ken Pizzini,
and Paolo Bonzini.
GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-sed@gnu.org>.
Be sure to include the word "sed" somewhere in the "Subject:" field.

If you get an error like “command not found”, you might need to install it.

On most modern Linux distributions, sed is part of the core utilities and should already be present. If, for some reason, it’s missing, you can install it using your distribution’s package manager.

For Debian-based systems (like Ubuntu, Mint):

$ sudo apt update
$ sudo apt install sed

For RHEL-based systems (like Fedora, CentOS, AlmaLinux): Modern versions use dnf:

$ sudo dnf install sed

Older versions might use yum:

$ sudo yum install sed

For macOS: macOS comes with a BSD version of sed. If you need GNU sed for its extended features (like -i without a mandatory suffix, or more advanced regular expressions), you can install it via Homebrew:

$ brew install gnu-sed

After installation with Homebrew, GNU sed is typically available as gsed. You might need to add it to your PATH or create an alias if you want to use sed to invoke GNU sed.

After any installation, verify it by running sed --version (or gsed --version if you installed GNU sed on macOS).

Installing from source is generally not necessary for sed unless you have very specific requirements or are developing sed itself. The version provided by your OS package manager is usually sufficient and well-integrated.

If you still wish to compile from source (e.g., to get the absolute latest version):

  • Download the source code: Visit the GNU sed official website to find the link to the latest stable source code tarball (e.g., sed-X.Y.Z.tar.gz).
  • Use wget or curl to download it. Replace X.Y.Z with the current version number.
  • $ wget https://ftp.gnu.org/gnu/sed/sed-X.Y.Z.tar.gz
  • Decompress and extract:
  • $ tar -xzvf sed-X.Y.Z.tar.gz
  • Navigate into the directory:
  • $ cd sed-X.Y.Z
  • Configure the build:
  • $ ./configure
  • This step checks your system for necessary dependencies and prepares the build files. If it reports missing dependencies, you’ll need to install them using your package manager.
  • Compile the source code:
  • $ make
  • Run tests (optional but recommended):
  • $ make check
  • Install the compiled binary: This usually requires superuser privileges.
  • $ sudo make install

Once installed, verify by running sed --version. Note that installing from source might place the binary in /usr/local/bin/sed, which might take precedence over the system sed in /bin/sed or /usr/bin/sed depending on your PATH configuration.