How to install cURL in Ubuntu? [SOLVED]


Ubuntu

Author: Omer Cakmak
Reviewer: Deepak Prasad

What is cURL?

cURL is a software project that provides a library and command line tool for data transfer using various protocols. The letter "c" in its name comes from the English word client.

The CURL project is divided into libcurl and cURL:

  • libcurl: A free client-side URL transport library that supports FTP, FTPS, Gopher, HTTP, HTTPS, SCP, SFTP, TFTP, Telnet, DICT, LDAP, LDAPS, IMAP, POP3, SMTP and RTSP protocols.
  • cURL: It is a command line tool for receiving or sending files using URL syntax. It uses the libcurl library. It supports the above mentioned internet protocols.

When cURL is installed, the libcurl package is also installed. Now let's see how to install the cURL package on Ubuntu.

 

How to install cURL?

Ubuntu repositories have the following version:

foc@ubuntu22:~$ sudo apt search curl

curl/jammy-updates,jammy-security,now 7.81.0-1ubuntu1.6 amd64 [installed,automatic]
  command line tool for transferring data with URL syntax

On the cURL official github page, the latest version is 7.86.0. Let's first explain the installation of curl from the Ubuntu repository and then from the source code.

 

Method-1: Install cURL From Repository

If you are using an older Ubuntu version, you can install with apt-get <package_name>. If you are using a new Ubuntu version, you can complete the installation with the following command:

foc@ubuntu22:~$ sudo apt install curl -y 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  apache2-data liblua5.3-0 ssl-cert
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libcurl4
The following NEW packages will be installed:
  curl
The following packages will be upgraded:
  libcurl4
...
Selecting previously unselected package curl.
Preparing to unpack .../curl_7.81.0-1ubuntu1.6_amd64.deb ...
Unpacking curl (7.81.0-1ubuntu1.6) ...
Setting up libcurl4:amd64 (7.81.0-1ubuntu1.6) ...
Setting up curl (7.81.0-1ubuntu1.6) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3) ...
Scanning processes...                                                   
Scanning linux images...

Installation completed successfully. Installed version:

foc@ubuntu22:~$ curl -V
curl 7.81.0 (x86_64-pc-linux-gnu) libcurl/7.81.0 OpenSSL/3.0.2 zlib/1.2.11 brotli/1.0.9 zstd/1.4.8 libidn2/2.3.2 libpsl/0.21.0 (+libidn2/2.3.2) libssh/0.9.6/openssl/zlib nghttp2/1.43.0 librtmp/2.3 OpenLDAP/2.5.13
Release-Date: 2022-01-05
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets zstd

 

Method-2: Install cURL From Source Code

NOTE:
It is recommended to perform the following operations with root user.

In this step, pull the package from the download address to your server with the help of wget for installation. Go to the download address and copy the link.

install cURL

 

Then type the link after the wget command:

root@ubuntu22:/home/foc# wget https://github.com/curl/curl/releases/download/curl-7_86_0/curl-7.86.0.tar.bz2
--2022-12-08 20:39:18--  https://github.com/curl/curl/releases/download/curl-7_86_0/curl-7.86.0.tar.bz2
Resolving github.com (github.com)... 140.82.121.4
Connecting to github.com (github.com)|140.82.121.4|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/569041/5fe80f56-4d9d-4c48-877e-643eb3aded14?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20221208%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20221208T173918Z&X-Amz-Expires=300&X-Amz-Signature=233bd43835850c9137bbf828bab73d0010b0b42287e28dd1f17f7688c7f6c934&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=569041&response-content-disposition=attachment%3B%20filename%3Dcurl-7.86.0.tar.bz2&response-content-type=application%2Foctet-stream [following]
--2022-12-08 20:39:18--  https://objects.githubusercontent.com/github-production-release-asset-2e65be/569041/5fe80f56-4d9d-4c48-877e-643eb3aded14?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20221208%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20221208T173918Z&X-Amz-Expires=300&X-Amz-Signature=233bd43835850c9137bbf828bab73d0010b0b42287e28dd1f17f7688c7f6c934&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=569041&response-content-disposition=attachment%3B%20filename%3Dcurl-7.86.0.tar.bz2&response-content-type=application%2Foctet-stream
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.110.133, 185.199.111.133, 185.199.109.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.110.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3118530 (3.0M) [application/octet-stream]
Saving to: ‘curl-7.86.0.tar.bz2’

curl-7.86.0.tar.b 100%[=============>]   2.97M  6.24MB/s    in 0.5s    

2022-12-08 20:39:19 (6.24 MB/s) - ‘curl-7.86.0.tar.bz2’ saved [3118530/3118530]

Unzip the downloaded compressed file to your current directory:

root@ubuntu22:/home/foc# tar -xvf curl-7.86.0.tar.bz2

Switch to the newly created directory:

root@ubuntu22:/home/foc# cd curl-7.86.0/

TLS type must be specified after the curl configure command. Some of them are listed below:

  • AmiSSL: --with-amissl
  • BearSSL: --with-bearssl
  • GnuTLS: --with-gnutls
  • mbedTLS: --with-mbedtls
  • NSS: --with-nss
  • OpenSSL: --with-openssl (also for BoringSSL and libressl)
  • rustls: --with-rustls
  • Schannel: --with-schannel
  • Secure Transport: --with-secure-transport
  • wolfSSL: --with-wolfssl

If no TLS is available --without-ssl should be used (Recommended). Configure with the following command:

root@ubuntu22:/home/foc/curl-7.86.0# ./configure --prefix=/usr/local --without-ssl

Then run "make" and "make install":

root@ubuntu22:/home/foc/curl-7.86.0# make
root@ubuntu22:/home/foc/curl-7.86.0# make install

Create necessary links and cache for newly added libraries with ldconfig:

root@ubuntu22:/home/foc/curl-7.86.0# ldconfig

Installation complete, check version:

root@ubuntu22:/home/foc/curl-7.86.0# curl -V
curl 7.86.0 (x86_64-pc-linux-gnu) libcurl/7.86.0
Release-Date: 2022-10-26
Protocols: dict file ftp gopher http imap mqtt pop3 rtsp smtp telnet tftp 
Features: alt-svc AsynchDNS IPv6 Largefile threadsafe UnixSockets

Curl package was installed with the latest version.

 

Basic Examples

You can find a few basic examples below. For more examples and information about curl, you can visit the article "15+ curl command examples in Linux [Cheat Sheet]".

To get up the www.golinuxcloud.com homepage:

foc@ubuntu22:~$ curl www.golinuxcloud.com

The output of this command will be the page content. If the specified address is not accessible or there is no address with this name, you will receive an error as follows:

foc@ubuntu22:~$ curl golinuxclou.com
curl: (6) Could not resolve host: golinuxclou.com

If you want to write the output to a file you can use the -o parameter:

foc@ubuntu22:~$ curl -o golinuxclou.html www.golinuxcloud.com
foc@ubuntu22:~$ curl -o golinuxcloud.html www.golinuxcloud.com
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

 

Summary

Ubuntu usually comes with a curl package installed. If it is not installed, you can install the curl package from the repository with the installation step.

If you need a specific or current curl for a need or project, you can install it from the source code.

 

References

curl.se - how to install curl and libcurl

 

Omer Cakmak

Omer Cakmak

He is highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

Leave a Comment