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 --listbashThe 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-configtext[!NOTE] Keep in mind that a single crate can install multiple binaries (e.g.,
cargo-updateinstalls bothcargo-install-updateandcargo-install-update-config). Also, crate names may differ from binary names (e.g., theripgrepcrate installs thergexecutable).
2. Basic Uninstallation with cargo uninstall#
To remove an installed package, use the standard cargo uninstall command:
cargo uninstall <package_name>bashPractical Example#
If you previously installed ripgrep and want to remove it:
cargo uninstall ripgrepbashCargo responds with the exact file removed:
Removing /Users/username/.cargo/bin/rgtextThe 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>bashFor example, to remove only cargo-install-update-config from the cargo-update crate:
cargo uninstall cargo-update --bin cargo-install-update-configbash3.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>bash4. 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/rgbashOn 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 --listmight 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:
- Shell Path Hashing: Your active shell session (Bash/Zsh) might cache binary locations in memory. Clear the cache:
- Zsh:
rehash - Bash:
hash -r
- Zsh:
- 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:
bashwhich <command_name>
Quick Command Reference#
| Action | Terminal Command |
|---|---|
| List all installed packages | cargo install --list |
| Uninstall a package | cargo uninstall <package_name> |
| Uninstall a specific binary | cargo uninstall <package_name> --bin <binary_name> |
| Uninstall from custom root | cargo uninstall --root <path> <package_name> |
| Default binary directory | ~/.cargo/bin/ (Unix) or %USERPROFILE%\.cargo\bin\ (Windows) |