
Curl is a powerful and versatile command-line tool used to transfer data from or to a server using various protocols like HTTP, HTTPS, FTP, and more. It’s widely used for testing APIs, downloading files, and interacting with web resources in real time. In this guide, we’ll walk through how to install Curl on Ubuntu 22.04 and explore some of the most commonly used Curl commands with practical examples.
Installing Curl on Ubuntu 22.04
Before you begin using Curl, you’ll need to make sure it’s installed on your system. Here’s how to install Curl on Ubuntu Desktop 22.04.
Step 1: Login with Root Privileges
Make sure you are logged in with a user who has sudo (root) privileges. If you’re using a virtual machine (VM), open the terminal.
Step 2: Install Curl Using APT
Run the following command in your terminal:
sudo apt install curl
The system will prompt you to confirm the installation. Press “Y” and then Enter to proceed.
After a few moments, Curl will be installed successfully on your machine.
Checking Curl Installation
To verify that Curl is installed and working properly, you can check its version by typing:
curl --version
Alternatively, you can use the shorthand version:
curl -VThis will display information about the installed Curl version, supported protocols, and features compiled with Curl.
Getting Help with Curl
If you’re new to Curl or want to explore its wide range of options, you can use the built-in help command:
curl --help
This command displays a list of all available options and flags you can use with Curl. It’s a quick way to understand what Curl is capable of without checking the manual every time.
Fetching Web Pages Using Curl
Curl is commonly used to fetch the contents of a webpage directly from the terminal.
Example:
curl http://example.com
or simply:
curl example.com
This will display the HTML source code of the website’s homepage right in your terminal. It’s particularly useful for web developers and testers.
Downloading Files with Curl
Curl can also be used to download files from the internet.
Download File with Original Name
Use the -O option to download a file and save it using its original file name:
curl -O https://code.jquery.com/jquery-3.7.1.min.js
This will download the jquery-3.7.1.min.js file and save it in your current directory.
Resume Interrupted Downloads
If your internet connection is interrupted during a download, you can resume the process using:
curl -C - -O http://releases.ubuntu.com/18.04/ubuntu-18.04-live-server-amd64.isoThis is especially useful for large files or slow connections.
Download File with Custom Name
To save a file with a custom name, use the -o option:
curl -o jquery.js https://code.jquery.com/jquery-3.7.1.min.js
This will save the downloaded file as jquery.js regardless of its original name.
After downloading, use the ls command to verify the file is present in your directory:
lsHandling Redirects with Curl
Some URLs might redirect you to another page (such as HTTP to HTTPS). To follow these redirects, use the -L option:
curl -L https://sampletest/url
This ensures you receive the final content after all redirections are followed.
Viewing Response Headers Only
If you want to view only the HTTP response headers of a URL (without the content), use the -I flag:
curl -I https://example.com
This will show details like HTTP status code, content type, server info, and more — useful for debugging and monitoring.
Sending HTTP Requests with Curl
Curl supports various HTTP methods, including GET, POST, PUT, DELETE, etc.
To send a basic GET request, use:
curl -X GET https://api.example.com/data
This is useful when testing APIs or performing automated scripts that require interaction with RESTful services.
Curl is more than just a simple download tool — it’s a powerful utility for developers, sysadmins, testers, and anyone who works with web resources or APIs. Whether you’re fetching a webpage, downloading a file, or sending data via HTTP requests, Curl makes these tasks quick and efficient from the terminal.
If you’re running Ubuntu 22.04, the installation process is simple and takes just a few seconds. Once installed, you can begin using Curl to explore the web from your command line with ease.
Quick Recap of Useful Curl Commands
| Command | Description | 
|---|---|
| curl --version | Check Curl version | 
| curl --help | Show help and options | 
| curl example.com | Show webpage source | 
| curl -O URL | Download file with original name | 
| curl -C - -O URL | Resume interrupted download | 
| curl -o filename URL | Download file with custom name | 
| curl -L URL | Follow redirects | 
| curl -I URL | View response headers | 
| curl -X GET URL | Send GET request | 
 
			 
			 
			 
			 
			
1 Comment
Comments are closed.