blog.dopana

Back

In the Rust ecosystem, cargo install <crate> is the standard way to install high-performance CLI applications like ripgrep, bat, eza, or zellij.

Over time, you might test different command-line utilities and end up with binary crates you no longer need. How do you remove them cleanly and free up your system path?

This guide explains how Cargo manages installed binaries, how to use cargo uninstall, and how to handle manual cleanup when needed.

ELI5: How Cargo Manages Installed Binaries#

Think of your operating system’s $PATH as a shared tool rack in a workshop:

  • When you run cargo install <crate>: Cargo downloads the crate source, compiles it into executable machine code, and hangs that tool onto your shared rack at $HOME/.cargo/bin. It also records an entry in its inventory book (.crates2.json).
  • When you run cargo uninstall <crate>: Cargo checks the inventory book, identifies the specific executable files associated with that crate, removes them from $HOME/.cargo/bin, and clears the log record.
flowchart TD
    subgraph Install["Installation (cargo install)"]
        CRATES_IO["Crates.io / Git Repository"] -->|Download & Compile| CARGO_BUILD["Cargo Compiler"]
        CARGO_BUILD -->|Copy binary| BIN_DIR["$HOME/.cargo/bin<br>(In System PATH)"]
        CARGO_BUILD -->|Record metadata| METADATA[".crates2.json<br>(Metadata Tracker)"]
    end

    subgraph Uninstall["Uninstallation (cargo uninstall)"]
        CMD["cargo uninstall <crate>"] -->|Look up| METADATA
        CMD -->|Delete executable| BIN_DIR
        CMD -->|Update & remove metadata| METADATA
    end

1. List Installed Binaries#

Before uninstalling any package, you can inspect all globally installed binary crates on your system.

Run the following command in your terminal:

cargo install --list
bash

The output displays each installed crate, its version, and the binary executables it provides:

bat v0.24.0:
    bat
ripgrep v14.1.0:
    rg
cargo-update v13.3.0:
    cargo-install-update
    cargo-install-update-config
text

[!NOTE] Keep in mind that a single crate can install multiple binaries (e.g., cargo-update installs both cargo-install-update and cargo-install-update-config). Also, crate names may differ from binary names (e.g., the ripgrep crate installs the rg executable).

2. Basic Uninstallation with cargo uninstall#

To remove an installed package, use the standard cargo uninstall command:

cargo uninstall <package_name>
bash

Practical Example#

If you previously installed ripgrep and want to remove it:

cargo uninstall ripgrep
bash

Cargo responds with the exact file removed:

Removing /Users/username/.cargo/bin/rg
text

The rg executable is immediately removed from your .cargo/bin directory, and Cargo’s tracking metadata is updated.

3. Useful Commands & Advanced Options#

3.1. Uninstall a Specific Binary by Name (--bin)#

If a crate installed multiple binaries and you only want to remove one of them, specify the binary name with --bin:

cargo uninstall <package_name> --bin <binary_name>
bash

For example, to remove only cargo-install-update-config from the cargo-update crate:

cargo uninstall cargo-update --bin cargo-install-update-config
bash

3.2. Uninstall from a Custom Root Directory (--root)#

If you originally installed the binary into a custom directory using the --root flag, provide the same root path when uninstalling:

cargo uninstall --root /custom/path <package_name>
bash

4. Manual Removal#

If metadata files are corrupted or you prefer direct file manipulation, you can manually delete binary executables from the Cargo bin directory.

Default Binary Locations#

  • macOS / Linux: $HOME/.cargo/bin/ (or ~/.cargo/bin/)
  • Windows: %USERPROFILE%\.cargo\bin\ (e.g., C:\Users\YourUsername\.cargo\bin\)

Manual Deletion Commands#

On macOS / Linux:

rm ~/.cargo/bin/rg
bash

On Windows (PowerShell):

Remove-Item "$HOME\.cargo\bin\rg.exe"
powershell

[!WARNING] Manual deletion removes the executable file, but the crate’s entry may temporarily remain in .crates2.json. As a result, cargo install --list might still display the package until metadata is refreshed or cleaned.

5. Troubleshooting Common Issues#

Issue 1: error: no package found with name ...#

This error occurs when you provide the binary name instead of the crate package name.

  • Incorrect: cargo uninstall rg
  • Correct: cargo uninstall ripgrep

Run cargo install --list to confirm the exact package name.

Issue 2: Command Still Works After Uninstallation#

If the command remains accessible in your terminal after running cargo uninstall, check these possibilities:

  1. Shell Path Hashing: Your active shell session (Bash/Zsh) might cache binary locations in memory. Clear the cache:
    • Zsh: rehash
    • Bash: hash -r
  2. Installed via Another Package Manager: The tool may have been installed using Homebrew (brew), APT, Pacman, or Scoop rather than Cargo. Verify the path with:
    which <command_name>
    bash

Quick Command Reference#

ActionTerminal Command
List all installed packagescargo install --list
Uninstall a packagecargo uninstall <package_name>
Uninstall a specific binarycargo uninstall <package_name> --bin <binary_name>
Uninstall from custom rootcargo uninstall --root <path> <package_name>
Default binary directory~/.cargo/bin/ (Unix) or %USERPROFILE%\.cargo\bin\ (Windows)

References#