How to Install and Use curl in Linux

curl is a command-line tool for making requests across the internet. It can be used to either get data from or post data to a remote server. It works with the HTTP, HTTPS, SCP, SFTP and FTP protocols and can be configured to resume and run on limited bandwidth as well as make authenticated and proxied connections.


In this guide, we will learn how to install and use curl in the Linux command-line. We will also cover some practical examples that you may want to use curl for.


How to Install curl

curl comes with almost every Linux distribution so it is unlikely you will need to install it. To test if curl is installed type curl into your command-line


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


You should see something like the above if curl is installed. If you get "command not found" or something along those lines you can install it by running the following commands on Ubuntu or Debian:


sudo apt update
sudo apt install curl


or on Fedora and CentOS:


sudo yum install curl


The curl Syntax

curl takes an optional set of options followed by the remote URL.


curl [options] [URL]


How to Perform an HTTP GET Request

The most basic way to use curl is by performing an HTTP GET request. To do that type curl followed by a domain name into the command-line.




Return the HTTP Response Headers

If you need to get the HTTP response headers from a GET request supply the -i flag before the domain.


curl -i


To return the headers only, capitalise the -I flag.


curl -I


Save the Output to a File

In some cases, we will want to download the contents of a remote address and save it to a file locally. This is done by adding the -o flag followed by the name of the file to save and finally the remote resource.


curl -o jquery.js


To save a file while keeping its original name capitalise the -0 flag:


curl -O jquery.js


Resume a Download

Internet connections go down from time to time and if you are in the middle of downloading a large file using curl the process will break. Fortunately, curl can resume the download when you are back online if you add the  -C - option.


curl -C - -O jquery.js


Follow Redirects

If you don't know the canonical address for a domain you can add the -L option to follow redirects until it reaches the final destination.


curl -L


Use a Custom User-Agent

Maybe the site you are trying to access only allows certain user-agents to connect, or you need to test your own systems based on different user-agents - curl can connect with a custom user-agent for those cases. Add the -A flag followed by the user-agent in "" (quotation marks).


curl -A "Mozilla/5.0 (Linux; Android 10; SM-A505U1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Mobile Safari/537.36 X-Middleton/1"


Set Bandwidth Limit

Sometimes it may be necessary to limit the transfer speed of a curl download to save bandwidth for other tasks. To do this add the --limit-rate flag followed by the bandwidth limit. This can in b (bytes), k (kilobytes), m (megabytes) or g (gigabytes.)


curl --limit-rate 2m -O -L


How to Perform an HTTP POST request

You can change the request method using the -X flag followed by the name of the request type. You could perform an HTTP POST like this:


curl -X POST


To pass data with the POST request, use the -d flag and put the data inside "" (quotation marks).


curl -d "name=john&age=22" -X POST


note - you can pass data from a file on your machine by using -d "@path-to-file.txt"


How to Perform an HTTP PUT request

A PUT request is done in the same way POST in curl


curl -X PUT


How to use HTTP Authentication

You can access URL's that require HTTP authentication using the -u flag followed by your username and password separated by : (colon).


curl -u username:password


Transfer Files Using FTP

As mentioned at the beginning, curl can work with multiple protocols. To use them we just have to supply the correct protocol in the address. Since FTP will almost certainly require authentication VIA a username and password let's also supply them in the example.


curl -u username:password


After logging in you will see a list of files and directories. To download a file using FTP supply a path to it.


curl -u username:password


Uploading is done by passing the name of the file you wish to upload after the -T flag.


curl -T -u username:password


Connect VIA Proxy

It is possible to transfer data VIA a proxy using curl. This is done by passing in the -x flag followed by the address and port of the proxy.


curl -x


If you need to authenticate yourself do so with the -u flag followed by a : (colon) separated username and password.


curl -u username:password -x


In some cases, you will need to supply a cookie to access data on a server. You can supply a cookie to send after the -b flag. This can either be a string or a file on your machine


curl -b "letmein=true"



You now know how to use curl in a variety of different ways. curl can be super useful for testing web applications you are working on or for things such as programmatically uploading/downloading multiple files. It is certainly a program you should spend the time getting used to.