Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Install Bear

Install Bear with your platform’s package manager:

# Debian / Ubuntu
sudo apt install bear

# Fedora
sudo dnf install bear

# Arch Linux
sudo pacman -S bear

# macOS (Homebrew)
brew install bear

# FreeBSD
pkg install bear

Then confirm it is on your PATH:

bear --version

Compare that version against the latest release. Distribution packages often lag several releases behind, so a problem you hit may already be fixed upstream; build the current release from source before reporting a bug. bear --help, or Command-line options, lists every flag once you have it installed.

For the full list of distributions that carry a Bear package, see the Repology page. Repology tracks the version each distribution ships; if yours lags behind, or does not package Bear at all, build it from source instead. Bear is not published on crates.io, so cargo install bear will not find it; cargo build --release plus the install script below is the source-build path.

Build from source

Follow INSTALL.md in the repository for prerequisites (the Rust toolchain and a C compiler) and the full steps. The short version:

cargo build --release
./scripts/install.sh

scripts/install.sh installs to /usr/local when run as root (for example under sudo), or $HOME/.local otherwise - a plain, unelevated run already gives you a working, no-sudo install. Override either default explicitly with PREFIX:

sudo PREFIX=/usr ./scripts/install.sh

DESTDIR for packaging, separately from PREFIX

scripts/install.sh accepts two different path variables, and they are not interchangeable. PREFIX is the final, on-system path; the bear entry script it installs embeds the driver path under it literally, so PREFIX must match where the package actually runs, not where it is being built. DESTDIR, when set, is a staging root prepended to every install path on top of PREFIX, for building a package without touching the real system; it must be an absolute path. Building a distribution package sets both together:

DESTDIR=/tmp/pkgroot PREFIX=/usr ./scripts/install.sh

LIBEXECDIR for distributions without libexec

By default the helper binaries and the preload library go into $PREFIX/libexec/bear/. Distributions without a libexec directory set LIBEXECDIR to the directory that should hold bear/ instead. The entry script then embeds the driver path under LIBEXECDIR rather than PREFIX, so it is an on-system path too, and DESTDIR still goes on top:

DESTDIR=/tmp/pkgroot PREFIX=/usr LIBEXECDIR=/usr/lib ./scripts/install.sh

It needs no matching build-time setting: bear-driver finds its siblings relative to its own location.

INTERCEPT_LIBDIR must match between build and install

On systems that use lib64 or another non-default library directory name, set INTERCEPT_LIBDIR for both the build and the install step, so bear-driver finds the preload library where it actually ends up:

INTERCEPT_LIBDIR=lib64 cargo build --release
INTERCEPT_LIBDIR=lib64 ./scripts/install.sh

Let the two commands disagree and Bear still installs without complaint, but preload interception silently fails at runtime: the dynamic linker cannot find the library at the path bear-driver expects, so it skips loading it and lets the build run anyway. Nothing about that failure is loud - the build succeeds, Bear exits 0, and the only symptom is a compile_commands.json that came out empty or suspiciously short, because a missing preload library is not one of the failures Bear itself reports (see Exit status). Bear on Linux has the matching commands for the common lib64 case.

Platform-specific notes

A distribution package or a source build both give you a working bear, but a few platforms have their own constraints on how Bear intercepts a build:

Next steps

Once bear --version works, follow Getting started with Bear for the first real run, or jump straight to a recipe for your build system.