How to Install and Use Curl on Ubuntu 20.04

Curl is a command line utility for transferring data to or from a remote server. With curl, you can upload or download data using one of the supported protocols, including HTTP, HTTPS, SCP, SFTP, and FTP.

This article explains how to install Curl on Ubuntu 20.04.

Installing Curl on Ubuntu

If you get the error curl: curl command not found when you try to download a file, it means the curl package is not installed on your Ubuntu machine.

curl is included in the standard Ubuntu 20.04 repositories. Installation is pretty straightforward:

sudo apt update
sudo apt install curl

Once the installation is complete, check by typing curl in your terminal:

curl

The output will look something like this:

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

All! You have successfully installed curl on your Ubuntu machine and you can start using it.

Using curl

When used without any option, curl prints the source code of the URL given as an argument to standard output.

For example, the following command will print the gnu.org homepage source in your terminal window:

curl https://gnu.org

To download a file using curl, use the -o or -O options.

The lowercase option -o allows you to specify the name of the saved file:

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

When called in uppercase -O, curl saves with the original filename:

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 HTTP headers of the specified URL:

curl -I https://www.gnu.org/
HTTP/1.1 200 OK
Date: Mon, 29 Jun 2020 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: Mon, 29 Jun 2020 07:10:35 GMT
Content-Type: text/html
Content-Language: en

Another common use case for curl is downloading files from password protected FTP servers:

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

Output

Curl is a versatile tool that allows you to send and receive data over the network. Installing Curl on Ubuntu is a fairly straightforward task.

For more information on how to use this tool, visit Curl Command Examples.

If you have any questions or feedback, do not hesitate to leave comments.

Sidebar