Last active
September 8, 2025 12:30
-
-
Save fuzzbuster/05a11cf6166071012c2cea175b6ce2ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e # Exit immediately if any command fails | |
| # 1. Update system package index | |
| echo "=== Updating system package index ===" | |
| sudo apt-get update -y | |
| # 2. Install basic compilation tools and dependencies (via system repositories) | |
| echo -e "\n=== Installing basic compilation tools ===" | |
| sudo apt install -y build-essential clang llvm libc6-dev linux-libc-dev git | |
| # 3. Check if rustup package exists in system repositories | |
| check_rustup_apt() { | |
| if apt-cache search ^rustup$ | grep -q rustup; then | |
| return 0 # Exists | |
| else | |
| return 1 # Does not exist | |
| fi | |
| } | |
| # 4. Select rustup installation method | |
| install_rustup() { | |
| echo -e "\n=== Select Rust toolchain installation method ===" | |
| if check_rustup_apt; then | |
| echo "1) Install rustup via system repository (may be outdated)" | |
| echo "2) Install rustup via official script (recommended)" | |
| read -p "Please choose installation method [1/2] (default 2): " choice | |
| choice=${choice:-2} | |
| if [ "$choice" -eq 1 ]; then | |
| echo -e "\n=== Installing rustup via system repository ===" | |
| sudo apt-get install -y rustup | |
| # Manual initialization required for repository-installed rustup | |
| rustup default stable | |
| else | |
| echo -e "\n=== Installing rustup via official script ===" | |
| curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | |
| fi | |
| else | |
| echo -e "\nrustup package not found in system repositories, will use official script" | |
| curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | |
| fi | |
| } | |
| # Execute installation | |
| install_rustup | |
| # 5. Load Rust environment variables | |
| echo -e "\n=== Loading Rust environment variables ===" | |
| CARGO_ENV="\(HOME/.cargo/env" | |
| if [ -f "\)CARGO_ENV" ]; then | |
| source "$CARGO_ENV" | |
| echo "Successfully loaded Rust environment from $CARGO_ENV" | |
| else | |
| echo "Warning: $CARGO_ENV not found. Rust commands may not work immediately." | |
| echo "Please restart your shell or run 'source $CARGO_ENV' after installation completes." | |
| fi | |
| # 6. Verify installation results | |
| echo -e "\n=== Verification ===" | |
| echo "Rustc version: $(rustc --version)" | |
| echo "Cargo version: $(cargo --version)" | |
| echo "Clang version: $(clang --version | head -n1)" | |
| echo "Rustup version: $(rustup --version | head -n1)" | |
| echo -e "\n=== Setup completed! Rust compilation environment is ready ===" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment