Installing curl on Alpine Linux is a small task, but it is an important one for administrators, developers, container maintainers, and anyone who needs reliable command-line access to web resources. Alpine is widely used because it is lightweight, secure, and efficient, especially in container environments. Because Alpine uses the apk package manager rather than apt, dnf, or yum, the installation process is slightly different from other Linux distributions.
TLDR: To install curl on Alpine Linux, update the package index with apk update, then install curl using apk add curl. Verify the installation with curl --version and test it against a trusted website such as https://example.com. If HTTPS requests fail, install or update ca-certificates and run update-ca-certificates.
Understanding Curl on Alpine Linux
curl is a command-line tool used to transfer data using protocols such as HTTP, HTTPS, FTP, SFTP, and many others. It is commonly used for API testing, downloading files, checking headers, debugging web services, and automating network operations in scripts. On Alpine Linux, curl is available from the official package repositories and can be installed quickly with the apk package manager.
Alpine Linux is intentionally minimal. Many base installations, especially Docker images such as alpine:latest, do not include curl by default. This keeps the image small, but it also means you must install curl before using commands that rely on it. Fortunately, the process is direct and predictable.
Prerequisites Before Installation
Before installing curl, make sure you have the following:
- Access to an Alpine Linux system, either on bare metal, a virtual machine, or inside a container.
- Root privileges, or permission to run administrative commands with
sudoif sudo is installed. - Network connectivity so the system can reach Alpine package repositories.
- Valid package repositories configured in
/etc/apk/repositories.
In many Alpine containers, you are already running as the root user. In that case, you do not need sudo. On a full Alpine installation, you may need to switch to root with su - or use administrative privileges depending on how the system is configured.
Step 1: Check Your Alpine Version
Although installing curl is similar across Alpine releases, it is a good practice to confirm which version you are using. Run:
cat /etc/alpine-release
This command prints the installed Alpine version. Knowing the version can help when troubleshooting repository issues or compatibility concerns. For most supported Alpine versions, the standard curl installation command remains the same.
Step 2: Update the Package Index
Before installing new software, update the local package index. This ensures apk has the latest list of available packages from the configured repositories:
apk update
If you are using sudo, run:
sudo apk update
This command does not upgrade all installed packages. It only refreshes the package database. If the command fails, check your internet connection and repository configuration. The repository file is located at:
/etc/apk/repositories
A typical repository entry may look similar to:
https://dl-cdn.alpinelinux.org/alpine/v3.20/main
https://dl-cdn.alpinelinux.org/alpine/v3.20/community
The exact version number may differ depending on your system.
Step 3: Install Curl with apk
Install curl using the following command:
apk add curl
With sudo, use:
sudo apk add curl
The package manager will resolve dependencies automatically and install curl along with any required libraries. On a minimal system, this may include SSL/TLS-related libraries required for secure HTTPS communication.
If the installation completes successfully, apk will return to the shell prompt without an error. Alpine package operations are generally fast because the distribution is compact and the packages are small.
Installing Curl in an Alpine Docker Container
Curl is frequently installed inside Alpine-based Docker images. If you are testing interactively, start an Alpine container with:
docker run -it --rm alpine sh
Inside the container, run:
apk update
apk add curl
For a Dockerfile, use a concise instruction such as:
FROM alpine:latest
RUN apk add --no-cache curl
The --no-cache option is recommended in Docker builds because it avoids storing the local package index in the final image layer. This helps keep the image smaller and cleaner. In many production Dockerfiles, the preferred command is:
RUN apk add --no-cache curl ca-certificates
Adding ca-certificates is especially useful when the container must make HTTPS requests to public services, private APIs, package registries, or cloud endpoints.
Step 4: Verify That Curl Is Installed
After installation, verify that curl is available by checking its version:
curl --version
A successful output usually includes the curl version, supported protocols, SSL backend, and enabled features. For example, you may see support for http, https, ftp, and other protocols depending on the Alpine package build.
You can also confirm that Alpine recognizes the installed package:
apk info -e curl
If curl is installed, the command returns:
curl
For more package details, run:
apk info curl
This provides information about the installed package, including description and dependency details.
Step 5: Test Curl with HTTP and HTTPS
The most practical verification is to make a real request. Start with a simple HTTP request:
curl http://example.com
Then test HTTPS:
curl https://example.com
If both commands return HTML content, curl is working. To view only the response headers, use:
curl -I https://example.com
This is useful for checking status codes, server headers, redirects, and content types. A normal response might include HTTP/2 200 or HTTP/1.1 200 OK.
Fixing HTTPS Certificate Problems
On minimal Alpine systems, curl may install successfully but HTTPS requests may fail with certificate-related errors. A common error looks like:
curl: (60) SSL certificate problem: unable to get local issuer certificate
This usually means the system does not have an up-to-date certificate authority bundle. Install or update certificate packages with:
apk add ca-certificates
update-ca-certificates
With sudo:
sudo apk add ca-certificates
sudo update-ca-certificates
After updating certificates, retry the HTTPS request:
curl https://example.com
Avoid bypassing certificate verification with curl -k or curl --insecure except for controlled troubleshooting. Disabling certificate verification weakens security and can expose scripts or systems to man-in-the-middle attacks.
Common Curl Usage Examples
Once curl is installed, you can use it for a wide range of administrative and development tasks.
- Download a file:
curl -O https://example.com/file.tar.gz - Save output to a specific file:
curl -o output.html https://example.com - Follow redirects:
curl -L https://example.com - Send a GET request to an API:
curl https://api.example.com/status - Send JSON data with POST:
curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' https://api.example.com/items - Show detailed connection information:
curl -v https://example.com
These commands are especially useful when diagnosing connectivity issues, validating API behavior, or testing services from inside a container or server environment.
Troubleshooting Installation Issues
If apk add curl fails, review the error carefully. The most common causes are repository problems, DNS failures, lack of network access, or permission issues.
If you see a permission error, confirm that you are running as root or using sudo. If you see repository fetch errors, test DNS resolution and internet access:
ping -c 3 dl-cdn.alpinelinux.org
If DNS is not working, check /etc/resolv.conf. In containers, DNS issues may be related to Docker daemon configuration, host networking, or corporate proxy settings.
If your environment requires a proxy, configure the appropriate variables before running apk or curl:
export http_proxy=http://proxy.example.com:8080
export https_proxy=http://proxy.example.com:8080
Then retry:
apk update
apk add curl
Uninstalling Curl from Alpine
If you no longer need curl, remove it with:
apk del curl
This removes the curl package. Alpine may retain dependencies if they are required by other installed packages. In container images, it is often better to install curl only in build stages if it is not needed at runtime. This reduces the final image size and limits unnecessary software exposure.
Security and Maintenance Considerations
Keeping curl updated matters because it handles network communication and secure connections. To upgrade installed packages on Alpine, run:
apk update
apk upgrade
In production environments, package updates should be tested before deployment. For containers, rebuild images regularly from current base images rather than relying indefinitely on old layers. This helps ensure that curl, SSL libraries, and certificate bundles remain current.
When using curl in scripts, prefer explicit options and safe handling of secrets. Avoid placing tokens directly in shell history, logs, or Dockerfiles. Use environment variables, secret management systems, or runtime injection methods when working with credentials.
Conclusion
Installing curl on Alpine Linux is straightforward: refresh the package index, install the package with apk add curl, and verify the result with curl --version and a real HTTP or HTTPS request. For secure connections, make sure ca-certificates is installed and current. Whether you are managing a server, building a Docker image, or troubleshooting an API, curl is a dependable tool that belongs in many Alpine-based workflows. By following these installation and verification steps carefully, you can use curl confidently and maintain a secure, reliable Alpine environment.