How to install ripgrep (rg): basic regex search, common flags, and rg vs grep

Install rg, run a first regex search, skim common flags, and know when grep still wins.

grep -r works in a repo, but it happily walks node_modules, needs more flags for a sane default, and regex metacharacters fight the shell. ripgrep (rg, Rust, BurntSushi) recurses by default, respects .gitignore, and packs daily search into short flags. This guide covers installing rg, literals and basic regex, common flags, and rg vs grep for hereink readers who pair it with fd and bat. For ignore-file depth, see our ripgrep and .gitignore article.

The query is how to install ripgrep for regex search and compare common flags to grep. You should finish with rg on PATH, a first search from the repo root, fluency with -n/-l/-i/-w, and when to keep /bin/grep.

installbrew · apt · dnf
searchliteral · regex
comparerg vs grep
install rgregex & flagsvs grep

What rg fixes

Repo search with fewer footguns

rg TODO recurses from here, skips ignored paths, and prints paths with line numbers. Less noise than grep -rIn TODO . on a large tree.

Works with fd and bat

fd lists paths, rg searches content, bat previews hits: rg -l pattern | xargs bat.

Upstream: github.com/BurntSushi/ripgrep. Run rg --version after install.

Install on macOS and Linux

  1. 1
    macOS (Homebrew)

    brew install ripgrep. Verify with which rg and rg --version.

  2. 2
    Debian / Ubuntu

    sudo apt update && sudo apt install ripgrep. The binary is rg.

  3. 3
    Fedora / Arch

    Fedora: sudo dnf install ripgrep. Arch: sudo pacman -S ripgrep.

  4. 4
    Windows (optional)

    winget install BurntSushi.ripgrep.MSVC or GitHub Releases. Examples below focus on macOS/Linux.

  5. 5
    First search

    At a Git root: rg "fn main" or rg TODO. Exit code 1 means no matches (not always an error in scripts).

Literals and basic regex

By default rg PATTERN treats PATTERN as a regex (Rust regex syntax). For dots and parentheses as literals, quote and escape, or use -F / --fixed-strings.

rg -F 'config.json' .
rg -F 'foo.bar' src/
rg '^import ' --type py
rg '\bError\b' logs/
rg 'function\s+(\w+)' -n app.js
rg 'TODO|FIXME' .
rg pattern src/ tests/

Common flags

rg -n pattern
rg -l pattern
rg -i pattern
rg -w Token
rg -C 3 panic
rg -t js pattern
rg -t rust 'unwrap\('
rg pattern -g '*.ts' -g '!*.min.ts'
rg -c pattern
rg -F -i 'License MIT'
rg --max-depth 2 pattern

Use --no-ignore or -u only when you mean to search ignored trees; default is safer in day-to-day dev.

rg vs grep

Goalripgrep (rg)grep
Recursive tree searchrg PATTERNgrep -rIn PATTERN .
Respect .gitignoreon by defaultnot built in
Fixed stringrg -F 'a.b'grep -F 'a.b'
Case insensitiverg -igrep -i
Files onlyrg -lgrep -rl
Context linesrg -C 3grep -C 3
Extension filterrg -t js or -g '*.js'grep -r --include='*.js'
Speedparallel, code-orientedfine for single files
POSIX minimal imagesextra installoften preinstalled

Keep /bin/grep for portable init scripts and one-off log files; use rg inside Git repos.

Good fit
Daily symbol search in repos, pairing with fd/bat, skipping vendor dirs by default.
Not ideal
Tiny containers with no extra binaries, or scripts that must stay strict POSIX—grep still wins.
Overlap with the .gitignore ripgrep article?

That post goes deep on ignore rules; this one focuses on install, regex basics, flags, and grep comparison.

Can rg replace sed for edits?

No—rg searches only. Use your editor, sd, or careful sed. rg -l first to scope files.

Why quote patterns in the shell?

Unquoted *, ?, and $() expand before rg runs. Single quotes around the pattern are the easy default.

After the search, align the design

Module boundaries are easier on a shared board. See create a space.

Start a room