Installing and Using Curl on Linux Like a Pro

Linux TLDR
Last Updated:
Reading time: 4 minutes

Curl is an amazing open source command-line tool and a library for transferring data with URLs (Uniform Resource Locators). It provides support for 26 protocols and allows you to send requests and retrieve responses through these protocols.

The majority of Linux distributions provide curl out of the box. Unfortunately, if your current Linux distribution does not include it or you have accidentally removed it, don’t worry.

In this article, you will learn how to install curl (and libcurl) on your current Linux system.

Tutorial Details

DescriptionCurl (and Libcurl)
Difficulty LevelModerate
Root or Sudo PrivilegesYes
Host System and ArchitectureUbuntu 22.10 (x64)
OS Compatibility Ubuntu, Manjaro, Fedora, etc.
Prerequisites
Internet RequiredYes

Differences between Curl and Libcurl

Now, when you interact with curl, on the other side of the coin, you will also find libcurl written on it, all though they are closely related but serve different purposes.

  1. Curl is a command-line tool and utility that allows you to transfer data from or to a remote server using multiple protocols like HTTP, HTTPS, FTP, SCP, SFTP, and 21 more.
  2. Libcurl is a client side library that provides an API for performing network-related operations in applications. It is written in C and supports all the 26 protocols mentioned earlier, providing networking functionalities in your program.

In a nutshell, curl is a command-line tool, and libcurl is a library that developers can use to add network functionality to their applications.

Now, leaving all the boring stuff here, let’s move on to the installation part for both tools.

How to Install Curl (and Libcurl) on Linux

It might be questionable why your Linux distribution did not include curl out of the box (except for its goal to become lightweight), but sure, it will be included in the repository.

So, all you have to do is open your terminal and execute the following command based on your Linux distribution to install it using your default package manager.

Installing Curl (and Libcurl) on a Debian or Ubuntu System

Execute the following command to install curl using the APT package manager:

$ sudo apt install curl -y

Execute the following command to install libcurl with the TLS backend you prefer.

$ sudo apt install libcurl4-openssl-dev -y

#OR

$ sudo apt install libcurl4-nss-dev -y

#OR

$ sudo apt install libcurl4-gnutls-dev -y

Installing Curl (and Libcurl) on a Red Hat or Fedora System

For Red Hat derivatives like Fedora and CentOS, you use the YUM package manager to install curl on your Linux system.

$ sudo yum install curl -y

And to install the libcurl development package that includes files, some documentation, etc., use the following command:

$ sudo yum install libcurl-devel -y

Installing Curl (and Libcurl) on a SUSE or openSUSE

For this distribution, you can use the Zypper package manager to install the curl command-line utility.

$ sudo zypper install curl -y

For the Libcurl development package, run:

$ sudo zypper install libcurl-devel -y

Installing Curl (and Libcurl) in an Arch or Manjaro System

Curl is provided in the core repository of Arch Linux; all you have to do is issue the following command:

$ sudo pacman -Sy curl

There is no official libcurl package provided for Arch based distributions.

Installing Curl (and Libcurl) on a Nix

Execute the following command to install curl using the Nix package manager on the NixOS distribution.

$ nix-env -i curl

There is no official libcurl package provided for NixOS distributions.

Verify the Curl Installation on your Linux System

Once the installation is successfully completed, execute the following command to ensure curl is installed and accessible from the command-line:

$ curl --version

Output:

Verifying the curl installation

How to Use the Curl Command on Linux

As I said at the beginning of this article, curl is capable of performing data transfer (sending requests and receiving responses from servers) with URLs in 26 different protocols.

So, We will look at a few examples of the usage of the curl command to make it easier for you to understand how you can take advantage of the curl command in your daily computing work.

πŸ“
Most of the URLs mentioned in the following examples are disposable and might not work in your case, as they are only for demonstration purposes.

1. Send a GET request to the server and display the received response:

$ curl https://ipinfo.io

2. If the referenced URL redirects to multiple pages, use the “-L” flag to display the final response.

$ curl -L https://linuxtldr.com/v2/users

3. Send a POST request with data in JSON format to the API endpoint:

$ curl -X POST -H "Content-Type: application/json" -d '{"name": "Jake", "age": 26}' https://linuxtldr.com/api

4. Download a file from a remote server and save it locally:

$ curl -O https://linuxtldr.com/wp-content/temp.zip

5. Download a file from a remote server and save it to your desired location:

$ curl -o ~/Downloads/temp.zip -O https://linuxtldr.com/wp-content/temp.zip

6. Upload a file (ex: “.zip“) to a remote server using multipart form data:

$ curl -F "file=@/home/linuxtldr/Downloads/temp.zip" https://linuxtldr.com/drive/

7. Include custom headers in the request before sending it to the server:

$ curl -H "Authorization: Bearer token123" https://linuxtldr.com/api

8. Authenticate to the secure API endpoint by providing basic authentication information:

$ curl -u username:password https://linuxtldr.com/api

9. Set a custom cookie in the header and send the modified request to the server:

$ curl -b "sessionid=123456" https://linuxtldr.com

10. Specify a specific HTTP method:

$ curl -X PUT https://linuxtldr.com/resource

11. Save the content of any website (that includes static HTML, CSS, and Javascript) in a “.html” file:

$ curl -o index.html https://linuxtldr.com

12. Set a custom user-agent in the header for the request:

$ curl -A "Mozilla/5.0 (X11; Linux i686; rv:109.0) Gecko/20100101 Firefox/115.0" https://linuxtldr.com

13. Test the response time of a server:

$ curl -w "Response time: %{time_total}\n" -o /dev/null -s https://linuxtldr.com

That’s all the necessary examples of the curl command that an informed Linux user should know.

However, if you are more eager to learn about the curl command, check the manual page using the “man curl” command.

Wrap Up

I hope this article might be useful for you, although I covered all the possible things a beginner or experienced user should know about the curl command.

And, The installation of the curl command using the source code is intentionally skipped as the process is tedious and might result in unexpected errors that might take a lot of time to resolve.

However, if you want me to include it or have any other questions or queries related to this topic, then come to the comment section and let’s have a coffee talk.

Till then, peace!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.