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
If Rust was removed successfully, your shell will typically report that these commands are not found.
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:
hash -r
Then try again:
rustc --version
If it still exists, you may have another Rust installation from a package manager or a manually installed binary.
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 byaptrustupremoves installations managed byrustup
Always uninstall with the same tool that installed the software.
4. Ignoring shell configuration
Sometimes PATH entries remain in files such as:
~/.profile
~/.bashrc
~/.zshrc
If you added Rust-related lines manually, remove them after uninstalling.
5. Thinking Rust is still installed because the shell cached the command
Your shell may cache executable locations.
Use:
hash -r
Then test again.
6. Manually removing directories before running the uninstall command
For example:
rm -rf ~/.rustup ~/.cargo
This may remove files, but it skips the normal cleanup path and can make troubleshooting harder. Use the official uninstall command first whenever possible.
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 | Clean, intended, removes managed files correctly | Requires rustup command to still work |
Manual deletion of ~/.cargo and ~/.rustup | Useful if rustup is broken | Easier to miss PATH cleanup or leave stale shell config |
Per-user install vs system package install
| Type | Installed Where | Managed By |
|---|---|---|
rustup install | Usually in ~/.cargo and ~/.rustup | Current user via rustup |
apt install | System directories | System package manager |
The key rule is simple: uninstall software with the same tool that installed it whenever possible.
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 rustup self uninstall first.
Do I need sudo to uninstall a rustup installation?
Usually no. A rustup installation is typically per-user and stored in your home directory.
Will this remove Rust for all users on the machine?
No. A normal rustup installation affects only the user who installed it.
Is uninstalling Rust the same as removing Ubuntu packages?
No. If Rust was installed via rustup, Ubuntu package commands like apt remove usually do not remove that installation.
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
Absolute Values in Rust: Using the abs() Method
Learn how to calculate absolute values in modern Rust with abs(), handle signed integer overflow, and choose safer alternatives.
Accepting Iterators in Rust Functions with impl Iterator
Learn how to write Rust functions that accept HashMap iterators using generic bounds or impl Iterator, avoiding trait object and lifetime errors.
Access Enum Variant Values in Rust with Pattern Matching
Learn how to extract and print values stored in Rust enum variants using match and if let pattern matching, with practical examples.