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.
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. Runrg --versionafter install.
Install on macOS and Linux
- 1macOS (Homebrew)
brew install ripgrep. Verify withwhich rgandrg --version. - 2Debian / Ubuntu
sudo apt update && sudo apt install ripgrep. The binary isrg. - 3Fedora / Arch
Fedora:
sudo dnf install ripgrep. Arch:sudo pacman -S ripgrep. - 4Windows (optional)
winget install BurntSushi.ripgrep.MSVCor GitHub Releases. Examples below focus on macOS/Linux. - 5First search
At a Git root:
rg "fn main"orrg 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 patternUse --no-ignore or -u only when you mean to search ignored trees; default is safer in day-to-day dev.
rg vs grep
| Goal | ripgrep (rg) | grep |
|---|---|---|
| Recursive tree search | rg PATTERN | grep -rIn PATTERN . |
| Respect .gitignore | on by default | not built in |
| Fixed string | rg -F 'a.b' | grep -F 'a.b' |
| Case insensitive | rg -i | grep -i |
| Files only | rg -l | grep -rl |
| Context lines | rg -C 3 | grep -C 3 |
| Extension filter | rg -t js or -g '*.js' | grep -r --include='*.js' |
| Speed | parallel, code-oriented | fine for single files |
| POSIX minimal images | extra install | often 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.