When developing shell scripts that require HTTP interactions, a common question arises: can we reliably assume cURL is present across Unix-like systems? While cURL is indeed widely available, its default installation status varies between distributions:
# Quick test to check cURL availability
if command -v curl &> /dev/null; then
echo "cURL is available"
else
echo "cURL not found - fallback needed"
fi
From recent testing and documentation review:
- macOS: Included since OS X 10.4 (Tiger)
- Ubuntu/Debian: Installed by default since Ubuntu 12.04
- CentOS/RHEL: Present in minimal installations since RHEL 6
- FreeBSD: Included in base system since 5.0-RELEASE
- Alpine Linux: Not in base image (requires apk add curl)
For robust scripts that need to work across environments:
#!/bin/sh
# Define download function with fallback
download_file() {
if command -v curl &> /dev/null; then
curl -sL "$1" -o "$2"
elif command -v wget &> /dev/null; then
wget -q "$1" -O "$2"
else
echo "Error: Neither curl nor wget available" >&2
exit 1
fi
}
# Example usage
download_file "https://example.com/data.json" "local_data.json"
Common installation commands across distributions:
# Debian/Ubuntu
sudo apt-get install curl -y
# RHEL/CentOS
sudo yum install curl
# Alpine Linux
apk add curl
# macOS (Homebrew)
brew install curl
- Always check for cURL availability at script start
- Provide clear error messages when requirements aren't met
- Consider including installation instructions in your documentation
- For critical systems, document the minimum required cURL version
While cURL's presence is increasingly common, truly portable scripts should either declare it as a requirement or implement fallback mechanisms. The trend among modern Unix-like systems is to include cURL by default, except for extremely minimal installations.
From my experience working across various Unix-like systems, cURL has become increasingly standard over the past decade. While it wasn't always guaranteed to be pre-installed, most modern distributions now include it by default:
# Checking cURL installation on most systems:
which curl || echo "cURL not found"
# Sample download using cURL:
curl -O https://example.com/datafile.zip
Here's a breakdown of where you'll typically find cURL:
- Linux (Debian/Ubuntu): Included in base installations since Ubuntu 12.04
- macOS: Pre-installed since OS X 10.4 (Tiger)
- FreeBSD/OpenBSD: Available in base system since 2010s
- Minimal/Containerized Systems: May require explicit installation
For production scripts that need maximum compatibility, consider this pattern:
#!/bin/bash
# Check for cURL or fall back to wget
if command -v curl &> /dev/null; then
DOWNLOAD="curl -sL -o"
elif command -v wget &> /dev/null; then
DOWNLOAD="wget -q -O"
else
echo "Error: Neither curl nor wget found" >&2
exit 1
fi
# Usage example:
$DOWNLOAD output.file https://example.com/data
In environments where you control the deployment (like Docker containers), explicitly declare the dependency:
# Dockerfile example for Debian-based systems
FROM debian:stable-slim
RUN apt-get update && apt-get install -y curl
Understanding why cURL often becomes the preferred choice:
Feature | cURL | wget | Python requests |
---|---|---|---|
HTTP/2 support | Yes | No | Yes |
Built-in compression | Yes | Limited | Yes |
Base system install | Common | Less common | Rare |