Installing and using cURL on Linux

In this tutorial, we will show you how to install and use cURL on a Linux server. cURL is a command line tool and library which can be used to transfer data from one to another server using various protocols. cURL comes with many features, such as user authentication, proxy, SSL connections, HTTP post, FTP upload, transfer resume, Metalink and more.

Install cURL

The chances are that cURL is already installed on your Linux server, to check it just run the `curl` command from the terminal and if you get the following output, it means that `curl` is already installed on your machine.

<code># curl
curl: try 'curl --help' or 'curl --manual' for more information</code>

If curl is not installed on your server you will see the following message:

<code># curl
bash: curl: command not found</code>

Installing `curl` is a no-brainier, just run the following command:

Ubuntu and Debian

<code>sudo apt install curl</code>

CentOS and Fedora

<code>sudo yum install curl</code>

Arch Linux

<code>sudo pacman -S curl</code>

Once the installation is completed, you can verify with:

<code>curl --version</code>

The output should be similar to the following:

<code>curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets
</code>

cURL examples

In the second part of this tutorial we will show you some of the most common uses of the `curl` command.

1. Save the URL output to a file

<code>curl -o index.html https://linuxhostsupport.com/</code>
<code>  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 43873    0 43873    0     0  61198      0 --:--:-- --:--:-- --:--:-- 61189</code>

2. Download a file and follow server redirects

<code>curl -O -J -L https://github.com/vuejs/vue/tarball/master</code>
<code>  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   124    0   124    0     0    223      0 --:--:-- --:--:-- --:--:--   223
100 1114k  100 1114k    0     0   800k      0  0:00:01  0:00:01 --:--:--  800k
curl: Saved to filename 'vuejs-vue-v2.5.0-0-g0948d99.tar.gz'
</code>

3. Retrieve HTTP Headers

<code>curl -I https://google.com</code>
<code>HTTP/1.1 301 Moved Permanently
Location: https://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Tue, 21 Nov 2017 18:39:30 GMT
Expires: Thu, 21 Dec 2017 18:39:30 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 220
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alt-Svc: hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35"</code>

4. Specify maximum transfer rate

<code>curl --limit-rate 500K -O http://mirror.pnl.gov/releases/16.04/ubuntu-16.04.3-desktop-amd64.iso</code>
<code>  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0 1514M    0 3247k    0     0   497k      0  0:51:54  0:00:06  0:51:48  500k</code>

Of course, if you use one of our Linux VPS Hosting services, you can always contact and ask our expert Linux admins (via chat or ticket) about cURL commands and anything related to cURL examples on Linux. They are available 24×7 and will provide information or assistance immediately.

PS. If you liked this post on how to use please share it with your friends on the social networks using the buttons below or simply leave a reply. Thanks.

Leave a Comment