Question

How to Uninstall Rust Installed with rustup on Ubuntu

rustrustup

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, and clippy
  • 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.

  • rustup is the cabinet itself
  • rustc, 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.

Take Quiz

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:

  • rustup removes installed Rust toolchains
  • cargo and rustc binaries managed by rustup are 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:

  1. The rustup program starts.
  2. It detects the Rust toolchains and components it manages.
  3. It asks for confirmation unless you pass -y.
  4. It removes files from directories such as ~/.cargo and ~/.rustup.
  5. It removes the rustup executable 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 rustup installation 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.

Take Quiz

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 rustup so 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 show or rustc --version.
  • Early troubleshooting: If cargo behaves 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:

  • rustup still 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:

  • apt removes packages installed by apt
  • rustup removes installations managed by rustup

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

TaskCorrect ToolExample
Uninstall Rust installed with rustuprustuprustup self uninstall
Remove Rust installed with Ubuntu packagesaptsudo apt remove rustc cargo
Remove a manually copied binaryManual deletionDelete the files you copied

rustup uninstall vs manual deletion

MethodProsCons
rustup self uninstallClean, intended, removes managed files correctlyRequires rustup command to still work
Manual deletion of ~/.cargo and ~/.rustupUseful if rustup is brokenEasier to miss PATH cleanup or leave stale shell config

Per-user install vs system package install

TypeInstalled WhereManaged By
rustup installUsually in ~/.cargo and ~/.rustupCurrent user via rustup
apt installSystem directoriesSystem package manager

The key rule is simple: uninstall software with the same tool that installed it whenever possible.

Take Quiz

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 with rustup
  • Installed with apt -> uninstall with apt
  • 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.

Take Quiz

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

  1. Check whether rustup, cargo, and rustc are currently available.
  2. Uninstall Rust using the rustup uninstall command.
  3. Refresh the shell command cache if needed.
  4. Verify that the Rust commands are no longer available.
  5. Inspect shell configuration files for leftover Rust PATH entries.
Take Quiz

Keep learning

Related questions

View more