How to Fix bash: sd: command not found in Minimal Linux Distributions

Developers and system administrators automating text transformations, code refactoring, and configuration patching frequently utilize sd, an intuitive, high-performance find & replace command-line tool written in Rust. Serving as a modern alternative to traditional sed and awk, sd features simpler regex syntax, regex capture group substitution, and significantly higher execution speed on massive text files. In fresh server images or minimal cloud container environments (Ubuntu Server, Debian Minimal, Alpine Linux), typing the command triggers the shell error: bash: sd: command not found because minimal distros do not bundle third-party Go or Rust utilities in base package groups.

Install sd via Official Distribution Repositories

Depending on your active Linux distribution, install sd using native package managers:

Ubuntu and Debian

# Available in modern Debian and Ubuntu repositories
sudo apt-get update
sudo apt-get install -y sd
sd --version

Alpine Linux

# Enable community repository in /etc/apk/repositories
sudo apk update
sudo apk add sd

Fedora and RHEL / CentOS

sudo dnf install -y sd

Arch Linux

sudo pacman -S sd

Install via Cargo (Rust Toolchain)

If you operate an enterprise or minimal distribution without native packaging:

# Install using Cargo Rust package manager
cargo install sd

# Ensure cargo bin directory is in your active PATH
export PATH=$PATH:$HOME/.cargo/bin
echo 'export PATH=$PATH:$HOME/.cargo/bin' >> ~/.bashrc

Verify Regex Substitution Syntax

Unlike sed, sd does not require complex escaping for delimiters or capture groups:

  1. To replace string A with string B across a file in-place:
    sd 'old_pattern' 'new_pattern' config.ini
  2. To perform capture group replacement using clean indexing:
    echo "server: 192.168.1.10:8080" | sd '(\d+)\.(\d+)\.(\d+)\.(\d+)' '10.0.0.1'

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.