How to Install and Use ripgrep in Linux for Blazing-Fast Recursive Code Searching

Searching through sprawling source code repositories containing tens of thousands of files with classic Unix utilities like grep -r or find can bring development workflows to a crawl. Standard grep searches every directory blindly, wasting CPU cycles indexing huge node_modules trees, build caches, and binary blobs. ripgrep (invoked as rg), written in Rust by Andrew Gallant, combines Rust’s finite automaton regex engine with intelligent multi-threaded directory traversal, delivering search speeds orders of magnitude faster than classic search tools.

Why Developers Rely on ripgrep

Ripgrep has become the de facto standard code-searching engine across Linux distributions and powers internal search features inside tools like Visual Studio Code. Its advantages include:

  • Automatic Gitignore Respect: Silently ignores files and directories listed in .gitignore, .ignore, and global ignore rules by default.
  • Automatic Binary Detection: Skips compiled binaries, images, and non-text files without requiring special command flags.
  • Multi-Threaded Traversal: Distributes directory scanning across all available CPU cores dynamically.
  • Memory-Efficient Search: Uses memory-mapped files and streaming heuristics to keep RAM overhead minimal.
  • Smart Case Matching: Automatically searches case-insensitively unless your search pattern includes uppercase letters.

Installing ripgrep Across Linux Distributions

Ripgrep is packaged natively across all major distributions.

Installing on Ubuntu, Debian, and Linux Mint

sudo apt update
sudo apt install ripgrep

Installing on Arch Linux and Manjaro

sudo pacman -S ripgrep

Installing on Fedora and RHEL / CentOS

sudo dnf install ripgrep

Installing via Cargo (Any Distribution)

cargo install ripgrep

Core Syntax and Everyday Search Recipes

The basic usage syntax requires only the pattern you wish to locate:

rg "authentication_token"

Ripgrep recursively inspects the current directory, printing matching filenames, line numbers, and colour-highlighted matching lines.

1. Searching Specific File Types (-t)

Filter searches to specific languages without typing complex glob patterns:

# Search only inside Python files
rg -t py "def process_data"

# Search inside Rust and C++ files
rg -t rust -t cpp "calculate_hash"

View all built-in supported file type identifiers by running rg --type-list.

2. Inverting or Disabling Ignore Rules (-u)

If you need to inspect files normally excluded by .gitignore:

  • rg -u <pattern>: Unrestricted search (includes files in .gitignore).
  • rg -uu <pattern>: Includes hidden dotfiles and folders (like .env or .config).
  • rg -uuu <pattern>: Search everything, including binary files.

3. Context Control (-A, -B, -C)

Display surrounding lines of code to inspect function definitions or error handling:

# Show 3 lines of context around each match
rg -C 3 "handle_connection" server.py

4. Replacing Matching Text (–replace)

Combine pattern matching with string replacements across standard output streams:

rg "fast_io" --replace "standard_io"

ripgrep vs Standard grep Performance Comparison

Feature ripgrep (rg) Standard grep (-rn)
Search Engine Rust DFA regex engine GNU regex engine
Multi-Threading Enabled natively across cores Single-threaded execution
Ignore Rules Respects .gitignore automatically Requires manual --exclude-dir flags
Binary Handling Automatically skips binaries Matches raw binary bytes unless configured
Default Highlighting Coloured filenames and line numbers Monochrome unless aliased to --color=auto

Adopting ripgrep dramatically accelerates code exploration and terminal debugging, transforming multi-second search delays into instantaneous results.

Get the best tech tips delivered straight to your inbox.

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