# ensure_ripgrep

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/managed_tools/ensure_ripgrep)

Ensure a usable `rg` binary is available, installing if necessary.

Resolution order:

1. If the `system` installer is selected, return a non-managed `rg`
    found on `PATH`, or `None` when only the managed binary is present.
2. If a managed `rg` exists *and* matches `RIPGREP_VERSION`, return it.
3. Otherwise, if a system `rg` is on `PATH` and no managed binary
    exists, return its resolved path. This is gated on the *absence*
    of a managed binary: once a managed `rg` exists, the pinned
    version always wins, so a stale managed binary is re-fetched
    rather than deferring to a system `rg` and the resolved version
    stays deterministic.
4. If offline, return `None` so callers fall back to the existing
    notification + slow path.
5. If no managed asset matches the platform/arch, return a non-managed
    `rg` on `PATH` when one exists; otherwise raise
    `ManagedToolUnavailableError` so callers can explain that retrying will
    not help.
6. Otherwise download → SHA-256 verify → extract → install →
    prepend `BIN_DIR` to `PATH` → return the installed path. On a
    checksum mismatch, raises `ChecksumMismatchError` so callers can
    surface a loud notice. On a 404, raises `ManagedToolUnavailableError`;
    other failures log and return `None`.

A stale managed binary is never proactively deleted. The atomic
replace in `_install_ripgrep_sync` overwrites it on success, and on
failure the user is strictly better off keeping the older copy than
being left with no `rg` at all.

## Signature

```python
ensure_ripgrep() -> Path | None
```

## Returns

`Path | None`

Path to a usable `rg` binary, or `None` when one could not be

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/2f56309d821db4a0d06ee03959cf842c91b7f228/libs/code/deepagents_code/managed_tools.py#L492)