### Running rustup-init for initial setup Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/installation/other.md Command to run rustup-init when the package manager only provides this command, for initial setup. ```shell rustup-init ``` -------------------------------- ### Development build command Source: https://github.com/rust-lang/rustup/blob/main/doc/dev-guide/src/index.md Example of building and installing rustup into a temporary directory for development. ```bash cargo build mkdir home RUSTUP_HOME=home CARGO_HOME=home target/debug/rustup-init --no-modify-path -y ``` -------------------------------- ### Download previous version of rustup-init Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/installation/other.md This example shows how to download a specific previous version of rustup-init for a given target tuple. ```bash https://static.rust-lang.org/rustup/archive/{rustup-version}/{target-tuple}/rustup-init[.exe] ``` -------------------------------- ### Passing arguments to rustup-init via shell script Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/installation/other.md Examples of passing arguments to the rustup-init script through the shell. ```shell $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --help $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain nightly $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain none $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --profile minimal --default-toolchain nightly ``` -------------------------------- ### Installing a specific host toolchain Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/concepts/toolchains.md Example of installing a toolchain with a specific host target tuple, such as a 32-bit compiler or the MSVC toolchain on Windows. ```bash $ rustup toolchain install stable-x86_64-pc-windows-msvc ``` -------------------------------- ### Running rustup-init with tracing enabled Source: https://github.com/rust-lang/rustup/blob/main/doc/dev-guide/src/tracing.md Example command to run a rustup operation (e.g., 'show') with tracing enabled, using the built rustup-init binary. ```sh RUSTUP_FORCE_ARG0="rustup" ./target/debug/rustup-init show ``` -------------------------------- ### Correct .profile configuration for Mac with Homebrew and rustup Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/installation/already-installed-rust.md Example of how to configure the .profile file to ensure rustup proxies take precedence. ```bash eval $(/opt/homebrew/bin/brew shellenv) . $HOME/.cargo/env ``` -------------------------------- ### Basic Instrumentation Source: https://github.com/rust-lang/rustup/blob/main/doc/dev-guide/src/tracing.md Example of how to instrument a function with tracing. ```rust #[tracing::instrument(level = "trace", err(level = "trace"), skip_all)] ``` -------------------------------- ### Successful cargo version output (stable toolchain installed) Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/installation/already-installed-rust.md Example output of 'cargo +stable --version' when the stable toolchain is installed. ```text cargo 1.85.1 (d73d2caf9 2024-12-31) ``` -------------------------------- ### Example of incorrect command output Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/installation/already-installed-rust.md Illustrates the error message seen when cargo is not a rustup proxy. ```text error: no such command: `+stable` Cargo does not handle `+toolchain` directives. Did you mean to invoke `cargo` through `rustup` instead? ``` -------------------------------- ### Enable tab completion for Fish Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/installation/index.md Generates and installs the completion script for Fish. ```shell # Fish $ mkdir -p ~/.config/fish/completions $ rustup completions fish > ~/.config/fish/completions/rustup.fish ``` -------------------------------- ### Enable tab completion for Bash Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/installation/index.md Generates and installs the completion script for Bash. ```shell # Bash $ rustup completions bash > ~/.local/share/bash-completion/completions/rustup ``` -------------------------------- ### Install nightly toolchain with specific components Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/installation/index.md Installs the nightly toolchain, allowing downgrades to find necessary components, and includes 'clippy'. ```shell rustup toolchain install nightly --allow-downgrade --profile minimal --component clippy ``` -------------------------------- ### Enable tab completion for PowerShell v5.0+ Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/installation/index.md Generates and installs the completion script for PowerShell. ```powershell # PowerShell v5.0+ $ rustup completions powershell >> $PROFILE.CurrentUserCurrentHost # or $ rustup completions powershell | Out-String | Invoke-Expression ``` -------------------------------- ### Enable tab completion for Zsh Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/installation/index.md Generates and installs the completion script for Zsh. ```shell # Zsh $ rustup completions zsh > ~/.zfunc/_rustup ``` -------------------------------- ### Verify Rust installation Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/installation/index.md After installation, you can verify that Rust is installed correctly by checking the rustc version. ```console rustc --version ``` -------------------------------- ### Install GNU toolchain Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/installation/windows.md Install the GNU toolchain for use, even if not set as the default. ```bash $ rustup toolchain install stable-gnu ``` -------------------------------- ### APT installation of rustup Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/installation/other.md Command to install rustup using the APT package manager on Debian or Ubuntu. ```shell sudo apt install rustup ``` -------------------------------- ### Install with specific profile Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/concepts/profiles.md Command to directly select the profile used when installing a toolchain. ```console rustup install --profile ``` -------------------------------- ### Successful cargo version output (stable toolchain not installed) Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/installation/already-installed-rust.md Example output of 'cargo +stable --version' when the stable toolchain is not installed. ```text error: toolchain 'stable' is not installed ``` -------------------------------- ### Common rustup commands Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/examples.md A table of common rustup commands and their descriptions. ```bash rustup default nightly ``` ```bash rustup set profile minimal ``` ```bash rustup target list ``` ```bash rustup target add arm-linux-androideabi ``` ```bash rustup target remove arm-linux-androideabi ``` ```bash rustup run nightly rustc foo.rs ``` ```bash rustc +nightly foo.rs ``` ```bash rustup run nightly bash ``` ```bash rustup default stable-msvc ``` ```bash rustup override set nightly-2015-04-01 ``` ```bash rustup toolchain link my-toolchain "C:\RustInstallation" ``` ```bash rustup show ``` ```bash rustup toolchain uninstall nightly ``` ```bash rustup toolchain help ``` ```bash rustup man cargo ``` -------------------------------- ### Add Android target Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/cross-compilation.md Example of adding the Android target to rustup, showing the download and install process. ```console $ rustup target add arm-linux-androideabi info: downloading component 'rust-std' for 'arm-linux-androideabi' info: installing component 'rust-std' for 'arm-linux-androideabi' ``` -------------------------------- ### Build and open the book Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/README.md Builds the book and opens it in a web browser. ```console mdbook build --open ``` -------------------------------- ### Conditional Instrumentation with otel feature Source: https://github.com/rust-lang/rustup/blob/main/doc/dev-guide/src/tracing.md Example of instrumenting a function only when the 'otel' feature is enabled using cfg_attr. ```rust #[cfg_attr(feature="otel", tracing::instrument(level = "trace", err(level = "trace"), skip_all))] ``` -------------------------------- ### Serve the book Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/README.md Launches a local web server for the book with automatic rebuilding and browser reloading. ```console mdbook serve ``` -------------------------------- ### Running Jaeger Docker container Source: https://github.com/rust-lang/rustup/blob/main/doc/dev-guide/src/tracing.md Command to start a Jaeger all-in-one Docker container for OpenTelemetry tracing. ```sh docker run -d --name jaeger -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 -e COLLECTOR_OTLP_ENABLED=true -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p 16686:16686 -p 4317:4317 -p 4318:4318 -p 14250:14250 -p 14268:14268 -p 14269:14269 -p 9411:9411 jaegertracing/all-in-one:latest ``` -------------------------------- ### Legacy stderr output format Source: https://github.com/rust-lang/rustup/blob/main/doc/dev-guide/src/tracing.md Example of rustup's log output when RUSTUP_LOG is not set, mimicking older versions. ```console > rustup default stable info: using existing install for 'stable-aarch64-apple-darwin' info: default toolchain set to 'stable-aarch64-apple-darwin' stable-aarch64-apple-darwin unchanged - rustc 1.79.0 (129f3b996 2024-06-10) ``` -------------------------------- ### Install rustup from source Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/installation/other.md This command checks out the rustup git repository and builds it from source using cargo. ```bash git clone https://github.com/rust-lang/rustup cd rustup cargo run --release ``` -------------------------------- ### rustup dump-testament output Source: https://github.com/rust-lang/rustup/blob/main/doc/dev-guide/src/version-numbers.md Example output from the `rustup dump-testament` hidden command, showing detailed version information. ```shell $ rustup dump-testament Rustup version renders as: 1.18.3+15 (a54051502 2019-05-26) dirty 1 modification Current crate version: 1.18.3 Built from branch: kinnison/version-strings Commit info: 1.18.3+15 (a54051502 2019-05-26) Modified: CONTRIBUTING.md ``` -------------------------------- ### Tracing dependencies with RUSTUP_LOG=trace Source: https://github.com/rust-lang/rustup/blob/main/doc/dev-guide/src/tracing.md Example showing log lines from rustup's dependencies (e.g., hyper_util) when RUSTUP_LOG is set to 'trace'. ```console > RUSTUP_LOG=trace rustup update [..] 2024-06-16T12:12:45.569428Z TRACE hyper_util::client::legacy::client: http1 handshake complete, spawning background dispatcher task 2024-06-16T12:12:45.648682Z TRACE hyper_util::client::legacy::pool: pool dropped, dropping pooled (("https", static.rust-lang.org)) stable-aarch64-apple-darwin unchanged - rustc 1.79.0 (129f3b996 2024-06-10) nightly-aarch64-apple-darwin unchanged - rustc 1.81.0-nightly (3cf924b93 2024-06-15) 2024-06-16T12:12:45.693350Z INFO rustup::cli::rustup_mode: cleaning up downloads & tmp directories ``` -------------------------------- ### Using RUSTUP_FORCE_ARG0 Source: https://github.com/rust-lang/rustup/blob/main/doc/dev-guide/src/tips-and-tricks.md Example of how to use the RUSTUP_FORCE_ARG0 environment variable to simulate a specific binary when running with cargo run. ```console > cargo run --config env.RUSTUP_FORCE_ARG0=\'rustup\' -- show ``` -------------------------------- ### Example of linking and setting a custom toolchain Source: https://github.com/rust-lang/rustup/blob/main/doc/user-guide/src/concepts/toolchains.md Demonstrates linking a custom toolchain built from the rust-lang/rust repository and setting it as the default. ```bash $ rustup toolchain link my-toolchain ~/rust/build/x86_64-unknown-linux-gnu/stage2/ $ rustup default my-toolchain ``` -------------------------------- ### Custom logging mode with RUSTUP_LOG Source: https://github.com/rust-lang/rustup/blob/main/doc/dev-guide/src/tracing.md Example of rustup's log output when RUSTUP_LOG is set, using tracing_subscriber's builtin format. ```console > RUSTUP_LOG=trace rustup default stable 2024-06-16T12:08:48.732894Z INFO rustup::cli::common: using existing install for 'stable-aarch64-apple-darwin' 2024-06-16T12:08:48.739232Z INFO rustup::cli::common: default toolchain set to 'stable-aarch64-apple-darwin' stable-aarch64-apple-darwin unchanged - rustc 1.79.0 (129f3b996 2024-06-10) ```