Linux install command
How to install Rust on Linux using the rustup installation command including distribution-specific prerequisites alternatives and shell configuration
The Rust toolchain reaches Linux machines through one primary mechanism: the rustup installer. This page walks through the exact command, what every part of it does, and the Linux-specific considerations that make installation different from other platforms. If you are on Ubuntu, Fedora, Arch, or any other distribution, you will leave this page with a working Rust installation.
The Standard Installation Command
The official installation command for Rust on Linux comes from the rustup project. Open a terminal and run this line:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
The command downloads a shell script from sh.rustup.rs and immediately hands it to the sh interpreter, which runs it on your machine. The script detects your Linux distribution, downloads the correct rustup binary, installs the Rust toolchain, and configures your shell so that Rust commands work in future terminal sessions.
Breaking down the command from left to right, each piece exists for a specific reason. curl is the download tool that fetches files from the internet. The --proto '=https' flag forces curl to use only the encrypted HTTPS protocol for this connection. The --tlsv1.2 flag requires Transport Layer Security version 1.2 or newer, which protects the download from being tampered with during transit. The -sSf combination means silent mode with error messages shown and a hard failure if the server returns an HTTP error code. The pipe symbol | takes the downloaded script and feeds it directly into sh, the standard Unix shell interpreter.
What the Installer Actually Does:
The script downloaded from sh.rustup.rs is the official rustup installation script. It installs rustup itself, which is the Rust toolchain manager. rustup then installs the Rust compiler, the Cargo build tool, and supporting components. The script does not modify your system directories; everything lives inside your home folder.
Checking for curl Before You Start
Not every Linux distribution ships with curl pre-installed. Some minimal installations include only wget or neither download tool. Before running the installation command, check whether curl exists on your system:
which curl
If curl is present, the terminal prints a path such as /usr/bin/curl. If the command prints nothing, curl is not installed. Installing curl requires your distribution's package manager and administrator privileges, which is the sudo prefix on most systems.
Ubuntu, Debian, and their derivatives use the apt package manager. Install curl with:
sudo apt update
sudo apt install curl
The first command refreshes the package index. The second command installs curl from the official repositories.
Running the Installer Step by Step
When you run the curl command, the installer takes you through a short interactive flow. The installer script itself runs in under a minute, but the toolchain download that follows can take a few minutes on a typical broadband connection, and longer on a slow one.
Step 1: Download the Installer Script
Running the curl command downloads the rustup installation script from sh.rustup.rs and pipes it directly into the shell. You will not see the script itself because it executes immediately.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
The terminal displays a message confirming that rustup is downloading and setting things up.
Step 2: Respond to the Installation Prompt
The installer first shows the options it is about to use, then pauses and asks how you want to proceed:
Current installation options:
default host tuple: x86_64-unknown-linux-gnu
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with standard installation (default - just press enter)
2) Customize installation
3) Cancel installation
On an ARM machine the host tuple reads aarch64-unknown-linux-gnu instead of x86_64-unknown-linux-gnu. Everything else is the same.
Press Enter to choose the default option. The standard installation installs the stable toolchain into the .rustup directory inside your home folder, with Cargo's own files in .cargo.
Step 3: Wait for the Toolchain Download
rustup downloads the Rust compiler, the Cargo package manager, and supporting documentation. The download size depends on your profile selection but typically ranges from a few hundred megabytes to over a gigabyte for the complete profile.
The terminal shows progress messages as each component downloads. Do not close the terminal or interrupt the process.
Step 4: Update Your Shell Environment
The installer writes a line to your shell configuration file that adds the Rust binaries to your PATH. The PATH is the list of directories your shell searches when you type a command.
Apply the change immediately by sourcing the environment file:
source "$HOME/.cargo/env"
Alternatively, close and reopen the terminal. New terminals automatically read the updated configuration file.
Step 5: Verify the Installation
Confirm that Rust is working by checking the compiler version:
rustc --version
You should see output similar to rustc 1.100.0 (0ef1bc386 2026-11-09) with the version number depending on the current stable release.
The Interactive Installation Prompt Explained
The installer presents three numbered options. Understanding what each one does helps you make the right choice, especially if you are installing on a shared machine or have specific requirements.
The first option, the default, installs rustup and the stable Rust toolchain into ~/.rustup, with Cargo's files in ~/.cargo. The stable toolchain is the release channel recommended for most users. The installation does not require sudo because everything lives inside your home directory.
The second option opens a customization menu. From there you can change the installation directory, select a different default toolchain, choose a different profile, or modify the PATH configuration. This option exists for people who need precise control over their setup, such as installing Rust to a removable drive or avoiding automatic PATH modification.
The third option cancels the installation entirely without making any changes to your system. The downloaded script exits cleanly.
Default Is Usually Right:
If you see the prompt and do not have a specific reason to customize, pressing Enter to accept the default installation is almost always the correct choice. The standard setup works on every Linux distribution and can be reconfigured later if your needs change.
Non-Interactive Installation with the -y Flag
When you want to automate the installation process, such as in a shell script or a Docker container, the interactive prompt gets in the way. The -y flag tells the installer to accept all defaults without asking any questions.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
The -s in sh -s tells the shell to read commands from standard input rather than from a file. The -- separates the shell's own arguments from the arguments passed to the installation script. The -y flag then reaches the script and suppresses the interactive prompt.
When the command finishes, the installer prints a message telling you to source the environment file:
source "$HOME/.cargo/env"
This non-interactive mode is ideal for provisioning scripts where a human is not present to press Enter. The same flag appears in many cloud-init configurations and CI pipeline setup scripts.
Using wget Instead of curl
Some Linux systems have wget installed but not curl. The wget approach achieves the identical result with a different download tool.
The curl version downloads the script and pipes it directly to the shell:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
This is the command shown in the official Rust documentation and the one most tutorials use.
Both commands produce the same installation. Choose the tool that is already present on your system. If both are missing, install either one using your package manager and proceed.
Choosing Installation Options Up Front
The rustup installer accepts flags that let you skip the interactive customization menu entirely. You can combine these flags with the -y flag to produce a fully scripted installation with your chosen settings.
Selecting a different default toolchain uses the --default-toolchain flag:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
The stable value selects the stable release channel, which is the default anyway. Other values include beta for the upcoming release and nightly for the daily builds that contain experimental features.
Choosing a smaller installation footprint uses the --profile flag:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
The minimal profile installs only the compiler and Cargo, skipping documentation and extra components. The default profile adds the standard documentation, the rustfmt formatting tool, and the clippy linter. The complete profile includes every component available through rustup, which takes the most disk space but ensures every Rust tool is present. Beginners should use default or complete; the minimal profile is intended for constrained environments such as containers.
Custom Installation Directories
The default installation places Rust's files inside your home folder, split between ~/.cargo for Cargo's data and ~/.rustup for the toolchains. For most people, this is perfectly fine. However, if your home directory is on a slow network drive, or you want to share a single Rust installation across multiple users, you can redirect the installation to a custom location.
Two environment variables control where rustup installs files. CARGO_HOME sets the location for Cargo's own data: the binaries in bin/, the package registry, and the env file. RUSTUP_HOME sets the location for rustup's management files, including the toolchains/ directory where every installed toolchain lives and the settings.toml file that records your default toolchain.
export CARGO_HOME="/opt/rust"
export RUSTUP_HOME="/opt/rustup"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
The export statements set environment variables that persist only for the current terminal session. The installer reads these variables and places files accordingly. After installation, the Rust binaries live in /opt/rust/bin, and the installer writes a line into your shell configuration that sources /opt/rust/env, so new terminals still find them. The custom location changes where the files live, not how your shell finds them.
Custom Directories Only Last for One Terminal Session:
The export lines above only affect the terminal you typed them in. If you open a new terminal and run the installer again, or run a Rust command without first setting CARGO_HOME and RUSTUP_HOME there, the installer and the tools will use the default locations instead. For a permanent custom location, put the two export lines in your shell configuration file so every terminal sets them.
Custom directories are useful in specific scenarios. Shared development servers often place Rust in /opt so all users access the same toolchain. CI systems sometimes install to a workspace directory that gets cached between builds. If none of these situations apply, the default locations are simpler and require no extra configuration.
Package Manager Installation on Linux
Every major Linux distribution packages Rust in its official repositories. You can install Rust with apt, dnf, or pacman without ever touching the rustup script.
sudo apt install rustc cargo
The apt repositories include the Rust compiler and Cargo separately. You can install both together in a single command.
Repository Versions Can Be Significantly Outdated:
Distribution repositories are frozen at release time. Ubuntu LTS releases, for example, may ship a Rust version that is months old. New Rust features, bug fixes, and security patches appear in the official rustup channels first. If you plan to follow tutorials or use recent crates, the repository version may not be new enough.
The package manager approach also bypasses rustup entirely, which means you lose access to toolchain management features. You cannot switch between stable and nightly channels, install additional components, or manage multiple Rust versions side by side. The repository install gives you one Rust version, and it only updates when the distribution maintainers release an updated package.
For most learners and developers, the rustup installer is the better choice. The package manager approach makes sense only when your system administration policy requires all software to come from the official repositories.
PATH and Shell Configuration
After installation, your terminal needs to know where to find the Rust executables. The installer handles this automatically by appending a line to your shell configuration file.
The installer adds the line to the configuration files of the shells it finds on your system, and falls back to ~/.profile when a shell has no configuration file yet. In practice, that means the following. If you use zsh, the line goes into ~/.zshenv, which the installer creates if it does not exist. If you use bash and already have a ~/.bashrc file, the line goes there. If you use bash but have no ~/.bashrc yet, the installer does not create one. The line goes into ~/.profile instead, which your shell reads at login. Either way, the effect is the same: new terminals find the Rust commands. The line itself looks like this:
. "$HOME/.cargo/env"
This line sources the environment file that rustup created, which adds ~/.cargo/bin to your PATH. The PATH variable is a colon-separated list of directories that the shell searches when you type a command name.
To apply the change without opening a new terminal, source the environment file manually:
source "$HOME/.cargo/env"
The command reads the environment file and applies its changes to the current terminal session. After running it, typing cargo or rustc works immediately.
If you installed to a custom location, the installer still writes the sourcing line automatically, but it points at your custom env file (for example, /opt/rust/env) instead of $HOME/.cargo/env. If you use an unusual shell the installer does not recognise, it may skip that step. In that case, add the binary directory to your PATH yourself with a line like this in your shell configuration file:
export PATH="$CARGO_HOME/bin:$PATH"
Replace $CARGO_HOME with your actual custom path, or use the literal path directly:
export PATH="/opt/rust/bin:$PATH"
Forgetting to Source the Environment Breaks Rust Commands:
A common beginner mistake is running the installer, then immediately typing cargo in the same terminal and seeing command not found. The files are installed correctly, but the current terminal session has not loaded the updated PATH. Always run source "$HOME/.cargo/env" or open a new terminal after installation.
Verifying the Installation
The installation process finishes with a message telling you to source the environment file. After doing that, run a quick verification to confirm everything works.
Check the compiler version:
rustc --version
Expected output looks like this, with the exact version number depending on the current stable release:
rustc 1.100.0 (0ef1bc386 2026-11-09)
Check the Cargo version:
cargo --version
Expected output:
cargo 1.100.0 (3acc79c0c 2026-11-05)
Check the rustup version:
rustup --version
Expected output:
rustup 1.29.3 (edbc831ce 2026-11-02)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
Installation Confirmed:
If all three commands print version numbers without errors, the Rust toolchain is installed and working correctly. You are ready to create a new Rust project and start writing code.
The version numbers shown here change over time as new Rust releases arrive. Do not worry if your numbers are higher. The important thing is that each command responds with a version rather than an error.
Common Problems and Fixes
Installation issues on Linux tend to fall into a few predictable categories. Knowing what to look for speeds up the troubleshooting process.
The terminal reports curl: command not found. This means curl is not installed on your system. Install it using your package manager as described earlier, or switch to the wget installation method.
The terminal reports a permission denied error when running the install command. This rarely happens with the standard installation because everything writes to your home directory. If you see a permission error, verify that your user owns the home directory and that you are not running the command with unnecessary sudo.
The installation completes but rustc reports command not found. This is the PATH issue described earlier. Run source "$HOME/.cargo/env" in the current terminal, or close and reopen the terminal. If the problem persists in new terminals, check that the installer actually wrote the sourcing line to your shell configuration file.
SSL certificate errors appear during the download. This can happen on older Linux distributions with outdated certificate stores. Update your CA certificates using your package manager, then retry the command.
An existing Rust installation from a package manager conflicts with the rustup install. If Rust was previously installed via apt or another package manager, the two installations can shadow each other. Remove the package manager version with sudo apt remove rustc cargo or equivalent, then reinstall with rustup.
The installer downloads but hangs during the toolchain download. This is usually a network issue, particularly on slower connections or behind restrictive firewalls. The download continues in the background, but it may take several minutes. Check your network connection if the progress stops completely for an extended period.
The Installer Is Idempotent:
Running the installation command again on a system that already has Rust installed does not break anything. The installer detects the existing installation, updates rustup if needed, and confirms that everything is in place. This makes the command safe to include in provisioning scripts that may run multiple times.
Summary
The Linux installation command for Rust is a single curl invocation that downloads and runs the official rustup script. The command works on every Linux distribution and handles the heavy lifting of downloading the compiler, configuring the toolchain manager, and updating your shell environment.
The main decisions you face during installation are whether to accept the defaults, whether to use curl or wget, and whether to install through a package manager instead of rustup. For nearly every beginner, the default rustup installation using curl is the right choice. It installs the latest stable Rust, keeps everything inside your home directory, and gives you access to toolchain management features that package manager installations lack.
Once the installation completes and you have sourced the environment file, you have a working Rust toolchain. The next logical step is to explore the default toolchain settings and understand which tools the installation placed on your system.