Skip to content

Instantly share code, notes, and snippets.

@thisislawatts
Created July 3, 2025 18:39
Show Gist options
  • Save thisislawatts/4fac9fa61f145512d36721754f165fc6 to your computer and use it in GitHub Desktop.
Save thisislawatts/4fac9fa61f145512d36721754f165fc6 to your computer and use it in GitHub Desktop.
Download UV and verify checksum
#!/usr/bin/env bash
#
# UV Package Manager Installer
#
# This script automatically downloads and installs the latest version of uv,
# a fast Python package and project manager from Astral (astral-sh/uv).
#
# The script performs the following operations:
# - Fetches the latest release version from GitHub API
# - Downloads the appropriate binary tarball for x86_64 Linux
# - Downloads and verifies the SHA256 checksum
# - Extracts the binary and installs it to /usr/local/bin
# - Cleans up temporary files
#
# Dependencies:
# - curl
# - tar
# - sha256sum
# - sudo
# - jq
#
# Requirements:
# - x86_64 Linux system
# - Internet connection
# - Write access to /usr/local/bin (via sudo)
#
# Usage:
# ./install-uv.sh
#
set -euo pipefail
# Variables
REPO="astral-sh/uv"
ARCH="x86_64-unknown-linux-gnu"
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR"
echo "πŸ“¦ Fetching latest release version..."
LATEST_VERSION=$(curl -s https://api.github.com/repos/$REPO/releases/latest | jq -r '.tag_name')
echo "πŸ”– Latest version: $LATEST_VERSION"
echo "πŸ” Checking if uv $LATEST_VERSION is already installed..."
# Check if uv is installed and get its version
if command -v uv &> /dev/null; then
INSTALLED_VERSION=$(uv --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
echo "πŸ“‹ Currently installed version: $INSTALLED_VERSION"
if [[ "$INSTALLED_VERSION" == "$LATEST_VERSION" ]]; then
echo "βœ… uv $LATEST_VERSION is already installed and up to date!"
exit 0
else
echo "πŸ”„ Upgrading from $INSTALLED_VERSION to $LATEST_VERSION..."
fi
else
echo "πŸ“¦ uv not found, proceeding with installation..."
fi
# File names and URLs
BASENAME="uv-$ARCH.tar.gz"
CHECKSUM_FILE="$BASENAME.sha256"
BASE_URL="https://github.com/$REPO/releases/download/$LATEST_VERSION"
INSTALL_PATH="/usr/local/bin/"
# Download files
echo "⬇️ Downloading $BASENAME..."
curl -sSLO "$BASE_URL/$BASENAME"
echo "⬇️ Downloading checksum file..."
curl -sSLO "$BASE_URL/$CHECKSUM_FILE"
# Verify checksum
echo "πŸ” Verifying SHA256 checksum..."
if sha256sum -c "$CHECKSUM_FILE"; then
echo "βœ… Checksum verification passed."
else
echo "❌ Checksum verification failed!" >&2
exit 1
fi
# Extract the binary
echo "πŸ“‚ Extracting binary..."
tar -xOzf "$BASENAME" > uv
# Install the binary
echo "πŸ› οΈ Installing uv to $INSTALL_PATH (may require sudo)..."
sudo chmod +x uv
sudo mv uv $INSTALL_PATH
echo "πŸŽ‰ uv installed successfully at $INSTALL_PATH"
# Cleanup
cd /
rm -rf "$TMP_DIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment