Question
I installed Rust on an Ubuntu 16.04 machine using the following command:
curl https://sh.rustup.rs -sSf | sh
This is the installation method shown on the Rust installation page.
How can I completely uninstall Rust when it was installed through rustup?
Short Answer
By the end of this page, you will understand how rustup manages Rust installations, how to uninstall Rust safely, what files are usually removed, and how to verify that Rust has been removed from your system.
Concept
rustup is the official Rust toolchain manager. It does not just install a single rustc binary. Instead, it manages:
- Rust toolchains such as stable, beta, and nightly
- Components like
cargo,rustfmt, andclippy - Per-user configuration and downloaded files
- PATH setup so Rust commands work in the shell
When Rust is installed through rustup, uninstalling Rust usually means uninstalling rustup itself. That is because rustup is the thing that owns the Rust toolchains and related files.
This matters because uninstalling Rust is not always the same as deleting one executable. Modern language installers often manage multiple directories, shell configuration, and cached toolchains. Knowing which tool installed your language helps you remove it correctly and cleanly.
For a rustup-based installation, the standard way to uninstall is:
rustup self uninstall
This removes the rustup installation and the Rust toolchains it manages for the current user.
Mental Model
Think of rustup as a toolbox cabinet.
rustupis the cabinet itselfrustc,cargo, and toolchains are the tools stored inside it- Your shell PATH is the label that tells your system where the cabinet is
If you want to remove everything installed by that cabinet, you usually remove the cabinet, not one tool at a time.
So instead of manually deleting rustc or cargo, you use rustup self uninstall to let the manager clean up what it installed.
Syntax and Examples
The main uninstall command is:
rustup self uninstall
On some systems or older instructions, you may also see:
rustup self uninstall -y
The -y flag auto-confirms the prompt.
Example
rustup self uninstall
Typical result:
rustupremoves installed Rust toolchainscargoandrustcbinaries managed byrustupare removed- Rust-related files in the user's home directory are deleted
Common directories involved
These are the directories rustup usually manages:
~/.cargo
~/.rustup
If the uninstall command succeeds, these are usually removed automatically.
Verify removal
After uninstalling, check whether the commands still exist:
rustc --version
cargo --version
rustup --version
Step by Step Execution
Consider this sequence:
rustup self uninstall
rustc --version
Step 1: Run the uninstall command
rustup self uninstall
What happens:
- The
rustupprogram starts. - It detects the Rust toolchains and components it manages.
- It asks for confirmation unless you pass
-y. - It removes files from directories such as
~/.cargoand~/.rustup. - It removes the
rustupexecutable and managed Rust binaries.
Step 2: Check whether rustc still exists
rustc --version
Possible result:
command not found: rustc
That means the Rust compiler is no longer available in your shell.
Step 3: If the command still exists
Sometimes your shell still remembers an old command path. Refresh the shell state:
-r
Real World Use Cases
Knowing how to uninstall a toolchain manager is useful in real development work:
- Cleaning up a machine: Remove Rust from a workstation you no longer use for Rust development.
- Fixing a broken setup: Uninstall and reinstall when toolchains or PATH settings become inconsistent.
- Switching installation methods: Remove a
rustupinstallation before using a system package manager. - CI and containers: Keep build environments minimal by removing unused language toolchains.
- Shared systems: Clean up per-user development tools on lab machines or temporary servers.
This is not unique to Rust. Many ecosystems use managers that control the whole install, such as nvm, pyenv, or sdkman.
Real Codebase Usage
In real projects, developers usually do not uninstall Rust often, but they do rely on rustup as the standard toolchain manager.
Common patterns include:
- Version management: Using stable by default and nightly only for specific projects.
- Per-project overrides: Selecting a specific toolchain in a repository.
- Reproducible setups: Team members install Rust through
rustupso everyone uses the same toolchain style. - Resetting environments: If builds fail due to toolchain corruption, developers may uninstall and reinstall.
Related maintenance patterns:
- Validation: Check installed versions with
rustup showorrustc --version. - Early troubleshooting: If
cargobehaves unexpectedly, first verify which installation owns it. - Configuration cleanup: Remove old PATH entries from shell startup files when uninstalling.
Example check commands:
which rustc
which cargo
rustup show
These help identify whether your commands come from rustup or another installation source.
Common Mistakes
1. Deleting only rustc or cargo
Broken approach:
rm ~/.cargo/bin/rustc
Why it is a problem:
rustupstill exists- other toolchain files remain
- the installation becomes inconsistent
Better approach:
rustup self uninstall
2. Forgetting that Rust was installed per user
A rustup install usually lives in the current user's home directory, not system-wide.
That means uninstalling as another user will not remove your own Rust installation.
3. Assuming apt remove rustc will remove a rustup installation
If you installed Rust with rustup, this will usually not affect it:
sudo apt remove rustc
Why:
aptremoves packages installed byapt- removes installations managed by
Comparisons
| Task | Correct Tool | Example |
|---|---|---|
Uninstall Rust installed with rustup | rustup | rustup self uninstall |
| Remove Rust installed with Ubuntu packages | apt | sudo apt remove rustc cargo |
| Remove a manually copied binary | Manual deletion | Delete the files you copied |
rustup uninstall vs manual deletion
| Method | Pros | Cons |
|---|---|---|
rustup self uninstall |
Cheat Sheet
# Standard uninstall for rustup-based Rust
rustup self uninstall
# Auto-confirm uninstall
rustup self uninstall -y
# Check whether Rust commands still exist
rustc --version
cargo --version
rustup --version
# Find where commands come from
which rustc
which cargo
which rustup
# Clear shell command cache if needed
hash -r
Usually managed directories
~/.cargo
~/.rustup
If rustup is broken and manual cleanup is necessary
rm -rf ~/.cargo ~/.rustup
Then also inspect shell startup files for Rust PATH lines:
~/.profile~/.bashrc~/.zshrc
Rule of thumb
- Installed with
rustup-> uninstall withrustup - Installed with
apt-> uninstall withapt - Installed manually -> remove manually
FAQ
How do I uninstall Rust if I installed it with rustup?
Run:
rustup self uninstall
This is the standard uninstall command for a rustup-managed Rust installation.
Does rustup self uninstall remove cargo and rustc too?
Yes. If cargo and rustc were installed through rustup, they are removed along with the managed toolchains.
What if rustc still works after uninstalling?
You may have:
- a cached shell path
- another Rust installation from
apt - a manually installed binary
Try hash -r and check which rustc.
Can I just delete ~/.cargo and ~/.rustup?
You can if rustup no longer works, but the preferred method is first.
Mini Project
Description
Create a small shell-based cleanup checklist for a Rust development environment. This project helps you practice identifying a rustup installation, uninstalling it correctly, and verifying that it has been removed. It reflects a real maintenance task developers perform when resetting machines or fixing broken setups.
Goal
Build and run a short sequence of terminal commands that safely uninstalls a rustup-managed Rust installation and verifies the result.
Requirements
- Check whether
rustup,cargo, andrustcare currently available. - Uninstall Rust using the
rustupuninstall command. - Refresh the shell command cache if needed.
- Verify that the Rust commands are no longer available.
- Inspect shell configuration files for leftover Rust PATH entries.
Keep learning
Related questions
Accessing Cargo Package Metadata in Rust
Learn how to read Cargo package metadata like version, name, and authors in Rust using compile-time environment macros.
Associated Types vs Generic Type Parameters in Rust: When to Use Each
Learn when to use associated types vs generic parameters in Rust traits, with clear rules, examples, and practical API design advice.
Convert an Integer to a String in Rust
Learn the current Rust way to convert integers to strings, why `to_str()` no longer works, and when to use `to_string()` or `format!`.