How to Install and Use typos in Linux to Find and Fix Spelling Errors in Source Code

Typographical errors in source code are more than cosmetic embarrassments—they lead to broken public API endpoints, inconsistent database column names, confusing command-line flags, and unsearchable documentation. Traditional spell checkers like Aspell or Hunspell produce overwhelming noise when run against code repositories because they flag camelCase variables, hex codes, programming syntax, and acronyms. typos (also known as typos-cli) is a modern, blazing-fast source code spell checker written in Rust designed specifically for software projects, offering low false-positive rates, instant directory scanning, and automated interactive correction.

Why Use typos for Software Projects?

Unlike general-purpose prose dictionaries, typos is engineered to respect software architecture:

  • Code-Aware Tokenisation: Intelligently splits identifiers formatted in camelCase, snake_case, kebab-case, and SCREAMING_SNAKE_CASE without misinterpreting language keywords.
  • Near-Zero False Positives: Uses an opinionated correction dictionary that targets only unambiguous mistakes (e.g., correcting recieved to received or paramater to parameter), avoiding technical jargon collisions.
  • Multi-Format Transparency: Scans raw code files, markdown documentation, JSON schemas, YAML configurations, and commit messages seamlessly.
  • Blazing Performance: Built with multi-threaded file walking in Rust, auditing repositories containing hundreds of thousands of lines of code in fractions of a second.

Step 1: Installing typos on Linux

You can install typos via package repositories, pre-compiled binaries, or Cargo.

Option A: Install via Native Repositories

On Arch Linux and its derivatives:

sudo pacman -S typos

On Alpine Linux:

sudo apk add typos

Option B: Install via Pre-Compiled GitHub Release

For Debian, Ubuntu, Fedora, openSUSE, and enterprise Linux distributions:

# Download the latest binary archive
curl -LO https://github.com/crate-ci/typos/releases/latest/download/typos-v1.24.6-x86_64-unknown-linux-musl.tar.gz

# Extract the archive
tar -xzf typos-*-x86_64-unknown-linux-musl.tar.gz

# Move binary to executable path
sudo mv typos /usr/local/bin/
chmod +x /usr/local/bin/typos

Option C: Install via Rust Cargo

If you maintain a local Rust toolchain:

cargo install typos-cli

Verify installation by inspecting the version:

typos --version

Step 2: Scanning a Repository for Spelling Errors

Running typos without arguments audits the current working directory, respecting .gitignore rules automatically:

typos

If any typographical mistakes are identified, typos prints the file path, line number, character offset, incorrect word, and suggested replacement:

error: `occured` should be `occurred`
  --> src/database/connection.rs:42:18
   |
42 |     let error_occured = true;
   |               ^^^^^^^
error: `seperate` should be `separate`
  --> docs/architecture.md:15:32
   |
15 | We maintain three seperate deployment environments.
   |                   ^^^^^^^^

Scanning Specific Files or Folders

To target a single file or documentation subfolder:

# Scan only the documentation directory
typos docs/

# Scan a single configuration file
typos README.md

Step 3: Automatically Fixing Spelling Errors

Rather than manually navigating to each file and line to edit typos, instruct the tool to apply corrections directly:

Interactive / Global Replacement

To fix all identified spelling mistakes across the repository in a single command:

typos -w

The -w (or --write-changes) flag overwrites target files with corrected spellings in-place. You can then run git diff to review all adjustments before committing.

Step 4: Configuring Custom Project Dictionaries

Every engineering project uses domain-specific acronyms, third-party libraries, or specialised terms (such as internal codenames or cryptographic algorithms) that standard dictionaries might flag. Configure exceptions using a _typos.toml configuration file placed in the repository root.

Create the configuration file:

nano _typos.toml

Add custom rules to ignore specific words or file paths:

[default]
# Extend default dictionary with project-specific words
extend-words = { "teardown" = "teardown", "ansible" = "ansible", "nginx" = "nginx" }

# Ignore specific files or third-party vendor directories
extend-ignore-re = [
    "vendor/.*",
    "third_party/.*"
]

[default.extend-identifiers]
# Allow specific variable names that might look like typos
"htons" = "htons"

Step 5: Integrating typos into Git Pre-Commit Hooks and CI

Prevent new typos from entering production code by embedding typos into your continuous integration workflow or local pre-commit hooks.

Adding to Git Pre-Commit

Add typos to your .git/hooks/pre-commit script:

#!/bin/sh
typos --diff
if [ $? -ne 0 ]; then
    echo "Spelling errors detected! Run 'typos -w' to fix them before committing."
    exit 1
fi

Make the hook executable with chmod +x .git/hooks/pre-commit.

Maintaining Clean, Professional Codebases

Integrating typos into your Linux terminal workflow automates one of the most tedious aspects of code review. By eliminating embarrassing spelling mistakes across comments, documentation, and variable identifiers without false-positive headaches, you uphold exceptional engineering standards across all your software projects.

Get the best tech tips delivered straight to your inbox.

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