Debian

How to Install curl on Debian 12

How to Install Curl on Debian 12

In some cases, users might want to send a quick HTML request from the Command Line Interface (CLI), and for that purpose, Debian has multiple tools such as wget and curl. The curl (Client URL) is a versatile command line utility that uses the Libcurl library to allow users to exchange data between devices and servers through the terminal using any of the supported protocols, such as FTP, IMAP, HTTP, HTTPS, SMTP, and more. Users specify the URL using the curl utility to perform the actions accordingly and can add authentication credentials, set proxies and cookies, upload and download files, while sending a request through curl. Further, they can also use curl to troubleshoot the connection issues on your system.

In this guide, we will discuss:

How to Install curl on Debian 12

The first thing required for the installation of curl is to update the system repository using the below-given command:

sudo apt update && sudo apt upgrade

Once the repository is successfully updated, execute the following command to install the curl command line utility on Debian 12 from the default repository:

sudo apt install curl -y

Once the installation is completed, verify it by running the version command on your terminal; it will display the key information about the version of the curl with all the supported protocols:

curl --version

What is the Syntax of Using curl on Debian 12?

The curl can be used directly on the command line, or you can include it in the script. It is followed by the URL that provides the data. The general syntax for using the curl utility on Debian 12 is written below:

curl [URL]

You can also customize the curl command by including the various options in the general syntax:

curl [Options] [URL]

The number of options provided by the curl utility can be checked by executing the following command:

curl --help

Or you can open curl command manual on Debian by using the following command to view all options:

man curl

How to Use curl on Debian 12

You can use the curl command on Debian 12 to:

1: Using curl on Debian 12 to Fetch Web Page Information

If you use the curl command followed by the URL, it will provide the HTML content of the provided URL. For example, I am executing the curl command to fetch the web information of Google:

curl https://google.com

2: Using curl on Debian 12 to Display Headers of URL

If you use the curl command with the -I flag, it will return the HTTP headers of the entered URL, excluding the content of the URL:

curl -I https://www.google.com

3: Using curl on Debian 12 to Download Files From the Internet

You can use a curl command to download a file to your system directly from the website. You can use curl on Debian 12 to download:

1: Download a Single File From the Internet on Debian 12 Using curl

If you want to download a single file from the Internet using curl command on Debian 12, use the below-given syntax:

curl -o [file name] [URL]

OR

curl -O [URL]

In the above syntax:

-o flag downloads the file to the system with the provided name.

-O flag downloads the file with the same name as in the URL.

For example, I am downloading the .deb file of Google Chrome using the -O flag with the curl. It will download the file with the same name as it is in the URL:

curl -O https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

If you want to customize the name of the file, then use the -o flag followed by the file name and URL. In the below-given command, I have downloaded the .deb file of Google Chrome and saved it on my Debian 12 with the name of the google-chrome.deb:

curl -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

You can verify the successful installation of the file on Debian by using the below-given command:

ls

2: Download Multiple Files From the Internet on Debian 12 Using curl

You can also use the curl command on Debian to download multiple files; the basic syntax of using the curl command to download two files is written below:

curl -O url1 -O url2

In the below example command, I have downloaded the two files from the internet. One is the .deb file of Google Chrome and the other is the .deb file of the team viewer.

curl -O https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -O https://download.teamviewer.com/download/linux/teamviewer_amd64.deb

Verify the installation using the ls command:

Another method to download multiple files on the Debian 12 using curl command is to list all the URLs in a single file. To do so, create a file, paste the URLs in the created file, and save it using CTRL+X, add Y and press Enter:

After that, use the below-given syntax to download multiple files from the URL using the curl:

while read -r line; do curl -O $line; done < $HOME/<file_name>

Here, I am downloading all the files listed in the file-with-url.text:

while read -r line; do curl -O $line; done < $HOME/file-with-url.text

4: Using curl on Debian 12 to Add GPG key

The curl command is also used to add the GPG key of the packages to the repository of your Debian 12. For example, I have added the GPG key of Wine:

curl -s https://dl.winehq.org/wine-builds/winehq.key | sudo gpg --dearmor | sudo tee /usr/share/keyrings/winehq.gpg > /dev/null

5: Using curl on Debian 12 to Resume a Download

If for some reason the download has stopped, then you can resume it using the -C- flag with the curl as shown in the below-given command:

curl -C - -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

6: Using curl on Debian 12 to Specify a Maximum Transfer Rate

You can limit the transfer rate while downloading the file from the Internet using the –limit-rate flag while executing the command followed by the value expressed in gigabyte(g), megabyte(m), and kilobyte(k):

curl --limit-rate 1m -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

7: Using curl on Debian 12 to Test if a Website Supports HTTP/2

If you want to check whether a specific URL supports the HTTP/2 protocol, you can use the curl command with the -I flag followed by the URL. The -s flag runs the command in silent mode and displays only output. If it supports the HTTP/2 protocol, the output will be “HTTP/2 200”, otherwise it will display the “HTTP/1.1 200 OK”.

For instance, I have executed the following command to check whether the specified URL supports the HTTP/2 protocol:

curl -I --http2 -s https://linuxways.net/ | grep HTTP

How to Remove curl From Debian 12

To remove the curl utility from the Debian 12, execute the below-given command:

sudo apt remove curl -y

Conclusion

The curl is the powerful and widely used command line utility that is used to transfer the data to or from the servers. This command supports various options and protocols. You can install it on your Debian 12 using the “sudo apt install curl -y”, and customize the command using the various options. Using these options, you can send HTTP requests to fetch information from the website, download a single or multiple files from the internet, and more. We have explained the usage of the curl command with examples in the above post. We also discussed the command to remove the curl from your Debian 12 in this article.

 

Similar Posts