LinuxCommandLibrary

rustup-init.sh

Install and manage the Rust toolchain

TLDR

Download and run rustup-init to install rustup and the default Rust toolchain

$ curl https://sh.rustup.rs [[-sSf|--silent --show-error --fail]] | sh -s
copy

Download and run rustup-init and pass arguments to it
$ curl https://sh.rustup.rs [[-sSf|--silent --show-error --fail]] | sh -s -- [arguments]
copy

Run rustup-init and specify additional components or targets to install
$ rustup-init.sh --target [target] --component [component]
copy

Run rustup-init and specify the default toolchain to install
$ rustup-init.sh --default-toolchain [toolchain]
copy

Run rustup-init and do not install any toolchain
$ rustup-init.sh --default-toolchain [none]
copy

Run rustup-init and specify an installation profile
$ rustup-init.sh --profile [minimal|default|complete]
copy

Run rustup-init without asking for confirmation
$ rustup-init.sh -y
copy

SYNOPSIS

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh [OPTIONS]
./rustup-init.sh [OPTIONS]

PARAMETERS

-y, --no-confirm
    Proceed with the default installation options without requiring interactive confirmation from the user.

--no-modify-path
    Prevent the script from modifying the shell's PATH environment variable. Users will need to manually add $HOME/.cargo/bin to their PATH.

--default-host host-triple
    Specify the default host triple for the installation, such as x86_64-unknown-linux-gnu.

--default-toolchain toolchain-name
    Set the default toolchain to install (e.g., stable, beta, nightly, or a specific version like 1.78.0).

--profile profile-name
    Select an installation profile: default (rustc, cargo, std), minimal (rustc, cargo), or complete (all available components).

--component component-name, --add-component component-name
    Install a specific component (e.g., rust-docs, rustfmt, clippy). This option can be specified multiple times.

--target target-triple, --add-target target-triple
    Add a specific target for cross-compilation (e.g., wasm32-unknown-unknown). This option can be specified multiple times.

-v, --verbose
    Enable verbose output to display more detailed information during the installation process.

--version
    Display the version information for the rustup-init.sh script and exit.

-h, --help
    Show the help message for the script and exit.

--force
    Force the installation, even if rustup is already detected on the system. Useful for re-installations or updates.

DESCRIPTION

The rustup-init.sh script is the official bootstrap installer for rustup, the powerful Rust toolchain installer. It streamlines the process of downloading and configuring the Rust programming language environment on Unix-like operating systems, including Linux and macOS.

When executed, the script typically initiates an interactive installation, guiding the user to select a default Rust toolchain (e.g., stable, beta, nightly), essential components (such as the Rust compiler rustc, the package manager cargo, and documentation), and whether to automatically modify the system's PATH environment variable for ease of use.

For automated or non-interactive setups, rustup-init.sh is highly configurable. It supports a variety of command-line arguments and environment variables that allow pre-defining installation choices, making it ideal for integration into CI/CD pipelines or system provisioning scripts. By default, it installs Rust and Cargo to the user's home directory (~/.cargo) and updates shell configuration files to include ~/.cargo/bin in the PATH, enabling immediate access to Rust's command-line tools.

CAVEATS

The rustup-init.sh script requires an active internet connection to download Rust components and toolchains.

By default, the script modifies common shell profile files (e.g., .bashrc, .zshrc) to add $HOME/.cargo/bin to your PATH. If you use a non-standard shell setup or prefer manual PATH configuration, use the --no-modify-path option.

While rustup-init.sh handles most Rust-specific dependencies, ensure your system has fundamental build tools (like gcc or clang) installed, as they might be required for compiling certain Rust projects or native extensions.

NON-INTERACTIVE INSTALLATION

For automated environments such as Docker containers or CI/CD pipelines, combine the -y (or --no-confirm) option with specific --default-toolchain, --profile, --component, and --target flags. Alternatively, many options can be passed via environment variables prefixed with RUSTUP_INIT_ (e.g., RUSTUP_INIT_DEFAULT_TOOLCHAIN=nightly, RUSTUP_INIT_NO_MODIFY_PATH=1).

PROXY CONFIGURATION

If your system is located behind an HTTP/HTTPS proxy, it is essential to set the http_proxy and/or https_proxy environment variables correctly before executing the script. The underlying curl command used by the script respects these proxy settings.

UNINSTALLATION

To completely remove Rust and rustup from your system, use the rustup command that was installed: rustup self uninstall. This command will intelligently remove the .cargo and .rustup directories from your home folder and reverse any modifications made to your shell configuration files during installation.

HISTORY

rustup emerged as the de facto standard tool for managing Rust toolchains, succeeding earlier community efforts like multirust. It was developed by the Rust community to address the need for easy management of multiple Rust versions (stable, beta, nightly) and cross-compilation targets. The rustup-init.sh script was introduced as the initial bootstrapping mechanism, designed to simplify the very first installation of rustup itself, making the powerful capabilities of rustup accessible to a wide audience on Unix-like systems.

SEE ALSO

rustup(1), cargo(1), rustc(1)

Copied to clipboard