This page explains how to install bat on various operating systems and covers the basic usage patterns. For information about the core architecture and internal components, see Core Architecture.
bat can be installed through various methods depending on your operating system. The installation process makes the bat command available in your terminal for viewing files with syntax highlighting and other enhanced features.
Sources: README.md12-13 README.md186-466 doc/README-zh.md277-283
On Ubuntu (since 20.04 "Focal") and Debian (since Debian 11 "Bullseye"), you can install bat using the package manager:
Note: Due to a name clash with another package, the binary might be installed as batcat instead of bat. You can create a symlink or alias to address this:
For newer versions or older distributions, you can download and install the .deb package directly from the release page
Sources: README.md261-288 doc/README-ja.md186-210
| Distribution | Installation Command |
|---|---|
| Alpine Linux | apk add bat |
| Arch Linux | pacman -S bat |
| Fedora | dnf install bat |
| Gentoo | emerge sys-apps/bat |
| Void Linux | xbps-install -S bat |
| openSUSE | zypper install bat |
| Nix | nix-env -i bat |
Sources: README.md290-392 doc/README-ko.md254-323
You can install bat using Homebrew:
Alternatively, using MacPorts:
Sources: README.md399-413 doc/README-ja.md284-290
There are several methods to install bat on Windows:
Using WinGet:
Using Chocolatey:
Using Scoop:
Note: You'll need to install the Visual C++ Redistributable package as a prerequisite.
Sources: README.md415-450 README.md742-748
bat is available in the official Termux repositories:
Sources: doc/README-zh.md277-283
For any platform, you can:
aarch64-unknown-linux-musl, x86_64-apple-darwin, and x86_64-pc-windows-msvc.Sources: README.md452-468 .github/workflows/CICD.yml163-176
bat is designed as an enhanced replacement for the cat command, providing syntax highlighting, Git integration, and other useful features.
Sources: README.md6-7 README.md54-97
Display a single file in the terminal:
Display multiple files at once:
Read from stdin and determine syntax automatically (usually via shebang):
Read from stdin with explicit language specification:
Show non-printable characters (tabs, spaces, newlines):
Sources: README.md54-85 assets/manual/bat.1.in24-27
cat Replacementbat supports standard cat patterns:
Whenever bat detects a non-interactive terminal (piping into another process or a file), it acts as a drop-in replacement for cat and falls back to printing plain content.
Sources: README.md49-53 README.md87-97
By default, bat pipes its own output to a pager (e.g. less) if the output is too large for one screen. This behavior is controlled via --paging:
If you alias cat to bat, use alias cat='bat --paging=never' to maintain standard expectations.
Sources: README.md43-48 assets/manual/bat.1.in147-151
bat offers many options to customize its behavior. These are parsed using clap.
| Option | Description |
|---|---|
-A, --show-all | Show non-printable characters like space, tab, or newline |
-p, --plain | Alias for --style=plain. Use -pp to also disable paging |
-l, --language | Explicitly set the language for syntax highlighting |
-H, --highlight-line | Highlight specified line ranges (e.g. 40, 30:40) |
-n, --number | Only show line numbers (alias for --style=numbers) |
-d, --diff | Only show lines modified with respect to the Git index |
--tabs | Set the tab width (default 4) |
--wrap | Text-wrapping mode (auto, never, character, word) |
--color | Specify when to use colored output (auto, never, always) |
--theme | Set the color theme for syntax highlighting |
--style | Comma-separated list of style elements (e.g. grid, header) |
-r, --line-range | Only print specified line ranges |
Sources: assets/manual/bat.1.in20-162 assets/completions/bat.zsh.in26-77
fzfUse bat as a previewer for fzf. Use --color=always to force colorized output in the preview window:
Sources: README.md101-111
With find:
With fd:
Sources: README.md113-126
ripgrepWith batgrep, bat acts as the printer for ripgrep search results:
Sources: README.md127-130
gitView an older version of a file with syntax highlighting:
View lines around code changes:
Sources: README.md146-164
manSet MANPAGER to use bat as a colorizing pager for manual pages:
Note: The Manpage syntax is developed within the bat repository.
Sources: README.md178-191 doc/README-ja.md160-175
Sources: README.md700-739 assets/completions/bat.zsh.in121-134
The configuration file location can be found via bat --config-file. You can set a custom location using BAT_CONFIG_PATH.
Generate a default configuration file:
The file contains a list of command-line arguments, one per line:
Sources: README.md700-739 assets/manual/bat.1.in162-167
| Variable | Description |
|---|---|
BAT_THEME | Set the color theme |
BAT_PAGER | Determine which pager is used |
BAT_CONFIG_PATH | Path to the configuration file |
BAT_OPTS | Additional command-line options |
MANPAGER | If set to bat, colors man pages |
Sources: README.md627-635 README.md700-705 assets/manual/bat.1.in153-158
You can add custom syntaxes and themes to bat's configuration directory (bat --config-dir):
syntaxes and themes directories..sublime-syntax and .tmTheme files.bat cache --build to update the binary cache.Refresh this wiki