11 Jun Alpine Install Curl: How to Add Curl on Alpine Linux Quickly
Alpine Linux is tiny, fast, and a little bit spicy. It is the lightweight mountain goat of Linux distributions. But sometimes you open a fresh Alpine system and type curl, only to see an angry message saying it is not found. No panic. We can fix that fast.
TLDR: To install curl on Alpine Linux, run apk add curl as root. If your package list is old, run apk update first. In Docker, use RUN apk add --no-cache curl. After installing, test it with curl --version.
What Is curl?
curl is a command line tool. It lets you move data to and from servers. That sounds fancy. But it is really simple.
You can use curl to:
- Download a file.
- Call an API.
- Check if a website works.
- Test headers.
- Send data to a server.
- Debug network problems.
Think of curl as a tiny browser that lives in your terminal. It does not show pretty pages. It just grabs the data and shows it to you. Very direct. Very useful.
Why Alpine Does Not Always Include curl
Alpine Linux is built to stay small. Very small. That is one reason people love it. It is popular in containers because it saves space and starts quickly.
But there is a tradeoff. Alpine does not include every tool by default. Many base images are minimal. They include only what is needed to boot and run basic commands.
So if curl is missing, that is normal. Alpine is not broken. It is just traveling light.
The Quick Way to Install curl on Alpine
Here is the main command:
apk add curl
That is it. Nice and short.
The apk command is Alpine’s package manager. It is not the Android file type here. In Alpine, apk means Alpine Package Keeper. It installs, updates, and removes software packages.
If you are not logged in as root, use sudo if it is available:
sudo apk add curl
Many Alpine containers run as root by default. So you often do not need sudo there.
Step by Step: Install curl on Alpine Linux
Let us do it slowly. No stress. No wizard robe needed.
Step 1: Open the Terminal
Open your Alpine shell. If you are inside Docker, enter your container. If you are on a server, connect with SSH.
For SSH, it may look like this:
ssh user@your-server-ip
Use your real username and server address.
Step 2: Update the Package Index
This step is optional, but smart. It refreshes the package list.
apk update
If your system is brand new, this helps Alpine know where the latest packages are.
Step 3: Install curl
Now install curl:
apk add curl
Alpine will download curl and any needed dependencies. It should finish quickly.
Step 4: Check That curl Works
Run this:
curl --version
You should see version details. It may show supported features, protocols, and libraries. If you see that, curl is ready.
Install curl in Alpine Docker Images
Alpine is very common in Docker. This is where curl often goes missing. You may have a Dockerfile using something like:
FROM alpine:latest
Then your script tries to run curl. Boom. Not found.
Add this line to your Dockerfile:
RUN apk add --no-cache curl
The --no-cache flag is great for containers. It tells Alpine not to store the package index cache. This keeps your image smaller. Small images are happy images.
A simple Dockerfile may look like this:
FROM alpine:latest
RUN apk add --no-cache curl
CMD ["curl", "--version"]
Build it:
docker build -t alpine-curl-test .
Run it:
docker run --rm alpine-curl-test
If you see curl version output, you win. Please enjoy a tiny imaginary trophy.
Image not found in postmeta
Why Use --no-cache?
In normal Alpine systems, you may run:
apk update
apk add curl
That works fine. But containers are different. We want them clean and lean.
This command is better for Docker:
apk add --no-cache curl
It downloads the package index, installs curl, and avoids saving extra cache files. That means fewer layers and less junk.
Use --no-cache when building Docker images. It is a small habit with a nice payoff.
Install curl with HTTPS Support
The normal Alpine curl package includes modern support for HTTPS. So in most cases, this is enough:
apk add curl
But HTTPS also needs certificate files. These help curl trust secure websites.
If you get certificate errors, install the CA certificates package:
apk add ca-certificates
In Docker, you can install both together:
RUN apk add --no-cache curl ca-certificates
Then update certificate links if needed:
update-ca-certificates
Most of the time, installing ca-certificates fixes strange HTTPS problems.
Test curl with a Website
Now let us make curl do something useful. Try this:
curl https://example.com
You should see HTML output. It may look messy. That is fine. curl is showing the raw page code.
If you only want the response headers, use:
curl -I https://example.com
The -I flag asks for headers only. This is useful when you want to check status codes.
You may see something like:
HTTP/2 200
That means the site responded successfully. Nice.
Download a File with curl
curl is also great for downloads. To save a file with its original name, use -O:
curl -O https://example.com/file.txt
To choose your own file name, use -o:
curl -o myfile.txt https://example.com/file.txt
Small letter -o means “save as this name.” Big letter -O means “use the remote file name.” Tiny difference. Big result.
Use curl to Call an API
APIs love curl. Developers love curl. Servers tolerate curl. It is a whole thing.
Here is a simple API request:
curl https://api.github.com
You can also send JSON data:
curl -X POST https://example.com/api \
-H "Content-Type: application/json" \
-d '{"name":"Alpine Penguin"}'
This sends a POST request with JSON. The -H option adds a header. The -d option sends data.
Yes, the example name is Alpine Penguin. No, Alpine is not run by penguins. Probably.
Common Error: curl: not found
If you see this:
sh: curl: not found
It means curl is not installed. Install it:
apk add curl
If you are in Docker, add it to the Dockerfile. Do not install it manually inside a running container and forget about it. That change will vanish when the container is rebuilt.
Put the install command in the image build steps. Future you will be grateful.
Common Error: Permission Denied
If you run:
apk add curl
And Alpine says you do not have permission, you are not root.
Try:
sudo apk add curl
If sudo is not installed, switch to root:
su -
Then run the install command again.
In a Dockerfile, commands usually run as root unless the image changed the user. If the Dockerfile has a USER line before installing curl, move the install step above it.
Common Error: Package Not Found
If Alpine cannot find curl, your package repositories may not be set up or refreshed.
Try:
apk update
Then:
apk add curl
You can also check your repository file:
cat /etc/apk/repositories
It should contain Alpine repository URLs. If the file is empty or wrong, Alpine cannot find packages.
Image not found in postmeta
Remove curl from Alpine
Maybe you only needed curl for a quick test. Maybe you want to keep the system extra tiny. You can remove curl like this:
apk del curl
This uninstalls curl. Alpine may keep shared dependencies if other packages need them.
In Docker builds, a common trick is to install curl, use it, and remove it in the same layer. But be careful. Docker layers can keep old data if you split commands badly.
If you want a clean image, combine commands:
RUN apk add --no-cache curl \
&& curl -o /tmp/file.txt https://example.com/file.txt \
&& apk del curl
Only do this if the final container does not need curl at runtime.
curl vs wget on Alpine
Alpine often includes BusyBox tools. BusyBox may provide a small version of wget. So you might wonder, “Do I really need curl?”
Sometimes no. For a basic download, wget may be fine.
But curl is better for many tasks:
- Testing APIs.
- Sending custom headers.
- Posting JSON data.
- Debugging HTTP status codes.
- Working with many protocols.
- Writing repeatable scripts.
If you do serious web requests from the terminal, install curl. It is the little tool that does a lot.
Useful curl Commands to Remember
Here are some handy examples. Save them. Tape them to your monitor. Whisper them to your server.
curl --versionchecks the installed version.curl https://example.comfetches a web page.curl -I https://example.comshows response headers.curl -L https://example.comfollows redirects.curl -o file.txt URLsaves output to a file.curl -O URLsaves using the remote file name.curl -v URLshows verbose debug details.
The -v option is very helpful. It shows what curl is doing behind the curtain. If a request fails, try verbose mode. It is like giving curl a tiny flashlight.
Best Practice for Alpine Servers
On a normal Alpine server, this is a clean install flow:
apk update
apk add curl ca-certificates
curl --version
This gives you curl plus trusted certificates. It is simple. It is stable. It avoids common HTTPS trouble.
You may also upgrade packages first:
apk update
apk upgrade
apk add curl
Use upgrades carefully on production systems. Test first when possible. Servers dislike surprise parties.
Best Practice for Alpine Docker Images
In Docker, keep it short:
RUN apk add --no-cache curl ca-certificates
Place this near the top of your Dockerfile if many later steps use curl.
If curl is only needed during build, consider removing it after use. If your app needs curl at runtime, keep it installed.
Also, avoid running apk update in one Docker layer and apk add in another. Use --no-cache instead. It is cleaner.
Quick Cheat Sheet
- Install curl:
apk add curl - Install curl in Docker:
apk add --no-cache curl - Install certificates:
apk add ca-certificates - Check curl:
curl --version - Remove curl:
apk del curl - Update package list:
apk update
Final Thoughts
Installing curl on Alpine Linux is quick. The magic command is apk add curl. For Docker, the best command is apk add --no-cache curl.
Once curl is installed, you can test websites, download files, call APIs, and debug network issues. It is small, powerful, and friendly once you know the basics.
Alpine stays tiny. curl brings the web powers. Together, they make a great little toolbox.
Sorry, the comment form is closed at this time.