Website Vidya
Linux & ServersStep-by-Step Guide

How to Install and Use Curl on Ubuntu 24.04

Comprehensive tutorial to install and use curl on Ubuntu 24.04 LTS with practical examples for HTTP requests, file downloads, headers, and API debugging.

RR
Rajesh RayLead Systems Educator
Published:
5 min read
How to Install and Use Curl on Ubuntu 24.04
AI Executive SummaryCORE CIS AI

5 min read

Comprehensive tutorial to install and use curl on Ubuntu 24.04 LTS with practical examples for HTTP requests, file downloads, headers, and API debugging.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Installing Curl on Ubuntu 24.04
  • Step 2: Verifying Curl Installation and Supported Protocols
Grounded in full engineering runbookCORE CIS Ai Engine

Troubleshooting network connectivity, automating infrastructure scripts, downloading software binaries, and debugging RESTful APIs require a dependable, scriptable data transfer utility. When you install and use curl on ubuntu 24.04, you deploy the industry-standard data transfer utility powered by libcurl, capable of executing complex web interactions directly from your command-line terminal.

Unlike basic download utilities, curl provides granular control over the entire networking stack. You can manipulate HTTP request methods (GET, POST, PUT, DELETE), inject custom authentication tokens, inspect TLS certificate chains, follow multi-hop redirection chains, and measure exact network timing milestones down to the millisecond.

In this tutorial, you will learn how to verify and install curl on Ubuntu 24.04 LTS, master essential command-line flags, download files with resume capabilities, interact with JSON APIs, handle cookies and sessions, and diagnose network latency issues.

Advertisement

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat). The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

  • An active installation of Ubuntu 24.04 LTS (Desktop or Server).
  • A user account with active sudo administrative privileges.
  • Access to a command-line terminal and active network connectivity.

Step 1: Installing Curl on Ubuntu 24.04

While many Ubuntu installations include curl by default, minimal server images or container environments may omit it. Ubuntu 24.04 provides the latest stable package in its main repository.

Update your local package database index and install curl using the standard APT package manager.

# Refresh package repository index
sudo apt update

# Install curl package
sudo apt install -y curl

Step 2: Verifying Curl Installation and Supported Protocols

Verify that the curl binary is installed properly and check its version output. The --version flag reveals compiled features—including HTTP/2, HTTP/3, TLS backend (OpenSSL), and supported protocols.

Advertisement

Execute the following command in your terminal:

# Check curl version and feature flags
curl --version

Step 3: Basic HTTP GET Requests and File Downloads

By default, invoking curl with a URL prints the remote resource's raw HTML or text content directly to standard output (stdout).

To save the content to a file, you have two options:

• -o : Saves the downloaded content under a custom file name.

• -O: Saves the file using its remote filename extracted from the URL.

Advertisement
# Print webpage content to terminal stdout
curl https://example.com

# Save download to a custom filename
curl -o local_file.html https://example.com

# Download file saving under its remote filename
curl -O https://releases.ubuntu.com/24.04/SHA256SUMS

Step 4: Following HTTP Redirects and Resuming Downloads

Many modern web services issue 301 Moved Permanently or 302 Found redirects. By default, curl does not follow redirects unless you specify the -L (or --location) flag.

Additionally, if a large download is interrupted, use the -C - flag to resume the transfer from where it stalled rather than restarting from the beginning.

# Follow HTTP redirects automatically
curl -L https://ubuntu.com/download

# Resume an interrupted large file download
curl -L -C - -O https://releases.ubuntu.com/24.04/ubuntu-24.04-desktop-amd64.iso

Step 5: Inspecting HTTP Response Headers and Verbose Debugging

Sysadmins frequently need to inspect HTTP response status codes, caching directives, server banners, and cookies without downloading page bodies.

• -I (or --head): Sends a HEAD request to fetch only headers.

• -i: Prints both response headers and the response body.

• -v (or --verbose): Displays the full TLS handshake, IP resolution, request headers, and response headers.

# Fetch only HTTP response headers
curl -I https://ubuntu.com

# Verbose inspection of full TLS handshake and headers
curl -v https://api.github.com

Step 6: Sending HTTP POST Requests and JSON Payloads

When interacting with modern RESTful APIs, you often need to submit form data or JSON documents using HTTP POST.

Use -X POST to specify the method, -H to define custom HTTP headers (such as Content-Type: application/json), and -d to provide the data payload.

# Send a standard form-encoded POST request
curl -X POST -d "param1=value1&param2=value2" https://httpbin.org/post

# Send a JSON API request with headers
curl -X POST https://httpbin.org/post \
  -H "Content-Type: application/json" \
  -d '{"username": "admin", "service": "web-node01"}'

Step 7: Working with Authentication and Bearer Tokens

API endpoints and protected web consoles often require credentials. curl supports multiple authentication mechanisms:

• Basic Authentication: Use -u username:password.

• Bearer Token Authentication: Pass the token in the Authorization header.

# HTTP Basic Authentication
curl -u "apiuser:SecretPassword123" https://httpbin.org/basic-auth/apiuser/SecretPassword123

# Bearer Token API Authentication
curl -H "Authorization: Bearer my_secure_jwt_token_here" https://api.example.com/v1/servers

Step 8: Measuring Network Latency and Connection Performance

You can use curl's -w (write-out) option to extract detailed connection timing metrics—including DNS lookup time, TCP connect time, TLS handshake time, and time to first byte (TTFB).

Create a timing format file and benchmark an endpoint.

# Benchmark network connection milestones
curl -s -w "\nDNS Lookup: %{time_namelookup}s\nTCP Connect: %{time_connect}s\nTLS Handshake: %{time_appconnect}s\nTime to First Byte: %{time_starttransfer}s\nTotal Duration: %{time_total}s\n" -o /dev/null https://ubuntu.com

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

curl error: (60) SSL certificate problem: self signed certificate

Resolution: In development environments with self-signed certificates, use the -k (or --insecure) flag to bypass certificate validation. In production, always install the root CA certificate into /usr/local/share/ca-certificates/ and run sudo update-ca-certificates.

curl: (7) Failed to connect to host: Connection refused

Resolution: Verify that the remote service daemon is actively listening on the requested port using ss -tulpn, and ensure host firewalls (UFW) permit inbound traffic on that port.

curl: (3) URL using bad/illegal format or missing URL

Resolution: Ensure your URL includes the protocol scheme (e.g. https://example.com rather than just example.com), and wrap URLs containing query parameters in quotation marks to prevent shell character interpretation.

Security Best Practices and Hardening

Never pass sensitive plain-text passwords directly in CLI command arguments (-u user:pass) on shared multi-user systems, as passwords will appear in process listings (ps aux). Use configuration files (~/.netrc) with restricted permissions (0600) instead.

Avoid routinely using -k (--insecure) in production automation scripts, as disabling certificate validation exposes your traffic to man-in-the-middle attacks.

Always inspect and verify shell installation scripts before piping curl output directly into bash (curl -fsSL https://... | sudo bash).

Keep curl updated via sudo apt update && sudo apt upgrade curl to safeguard against published libcurl CVEs.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

3 FAQs
Wget is primarily designed for simple or recursive file downloads in the background, whereas curl supports bidirectional data transfer, dozens of protocols, custom headers, and complex API interactions.
Use the -s (silent) flag combined with -S (show errors if it fails): curl -sS -O https://example.com/file.zip.
Yes. Use the -x flag: curl -x socks5h://127.0.0.1:9050 https://check.torproject.org to route traffic through a local proxy.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Linux & Servers•

How to Install PDO Extension in PHP

PHP Data Objects (PDO) is one of the most important extensions in PHP for working with databases in a secure, consistent, and modern way. If you are building dynamic websites, APIs, CMS platforms, or enterprise applications, PDO is not opti...

RR
Rajesh Rai
Read More
Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout