Created
July 3, 2025 18:39
-
-
Save thisislawatts/4fac9fa61f145512d36721754f165fc6 to your computer and use it in GitHub Desktop.
Download UV and verify checksum
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
#!/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