Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to install and use Curl on Ubuntu 20.04, let's briefly understand – What is Curl?

Curl is a command-line tool and a library used to transfer data over various protocols like HTTP, FTP, and more. It allows users to send and receive data from servers, making it essential for tasks like downloading files or testing API endpoints.

Curl's versatility, simplicity, and wide range of supported protocols make it a popular choice among developers and system administrators. With curl, you can effortlessly handle data transfers and automate tasks, enhancing productivity and efficiency.

In this tutorial, we will explain how to install Curl on Ubuntu 20.04. We will also answer a few FAQs on how to install and use Curl on Ubuntu 20.04.

Advantages of Curl

  1. Versatility: Curl supports various protocols like HTTP, FTP, and more, allowing users to transfer data seamlessly.
  2. Simplicity: With its user-friendly command-line interface, Curl is easy to use for both beginners and experienced developers.
  3. Automation: Curl enables automated data transfers and tasks, saving time and effort for developers and system administrators.
  4. Wide Compatibility: Curl works on multiple platforms, including Windows, macOS, and Linux, ensuring compatibility across different systems.
  5. Extensibility: Curl's library and extensive options offer flexibility for customization, making it adaptable to a wide range of use cases.

Install Curl on Ubuntu

When using curl to download a file and get the error message curl command not found your Ubuntu computer does not have the curl package installed.

The standard Ubuntu 20.04 repositories include curl. The installation process is rather simple:

sudo apt update
sudo apt install curl

Check that the installation was successful by entering curl in your terminal:

curl

The final product will resemble this:

Output

curl: try 'curl --help' or 'curl --manual' for more information

Curl is now available for use on your Ubuntu computer after a successful installation.

How to Use curl

When used without any further options, curl publishes the URL's source code to the standard output.

For instance, the following command will display the gnu.org homepage's source code in your terminal window:

curl https://gnu.org

Curl's -o and -O options may be used to download files.

The name of the stored file may be specified using the lowercase -o option:

curl -o linux.tar.xz https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.0.5.tar.xz

Curl saves the file with its original filename when run with uppercase -O:

curl -O https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.0.5.tar.xz

With curl, you can also get only the URL's HTTP headers:

curl -I https://www.gnu.org/
Output

HTTP/1.1 200 OK
Date: Mon, 8 Aug 2022 07:10:35 GMT
Server: Apache/2.4.7
Content-Location: home.html
Vary: negotiate,accept-language,Accept-Encoding
TCN: choice
Strict-Transport-Security: max-age=63072000
Access-Control-Allow-Origin: (null)
Accept-Ranges: bytes
Cache-Control: max-age=0
Expires: Fri, 12 Aug 2022 07:10:35 GMT
Content-Type: text/html
Content-Language: en

Curl is often used to retrieve data from FTP servers that need a password:

curl -u FTP_USERNAME:FTP_PASSWORD ftp://ftp.example.com/file.tar.gz

FAQs to Install and Use Curl on Ubuntu 20.04

How can I check if Curl is installed on my Ubuntu 20.04 system?

Type curl --version in the terminal. If Curl is installed, it will display the version information; otherwise, it will prompt you to install it.

How do I use Curl to make an HTTP request?

Run the command curl [URL] in the terminal, replacing [URL] with the desired website or API endpoint. Curl will retrieve and display the response from the server.

Can I use Curl to download files from the internet?

Yes, you can. Use the command curl -O [URL] to download a file from the provided URL. The downloaded file will be saved in the current directory.

How do I pass headers or cookies with Curl requests?

To include headers, use the -H option followed by the header details. For cookies, use the -b option with the cookie data.

Is it possible to upload files using Curl?

Absolutely. Utilize the -F option followed by the parameter name and file path to upload files. Multiple files can be uploaded simultaneously.

How do I set a specific timeout for Curl requests?

Use the --connect-timeout option followed by the desired timeout duration in seconds to set a specific timeout for Curl requests.

How can I use Curl with authentication?

To authenticate with Curl, use the --user option followed by the username and password in the format username:password to access protected resources.

Conclusion

A curl is a flexible tool that enables network data transmission and reception. Curl installation on Ubuntu is a rather easy process.

Visit Curl Command Example, for more information about the working of this tool.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.