How to Install and Use Curl on Ubuntu 24.04?


Curl is an efficient tool that transfers data with the syntax of URL. It supports protocols containing FTP, HTTPS, HTTP, and more. The installation of Curl on Ubuntu 24.04 serves a critical role in system administration and development tasks. Its versatility allows for data transmission to or from a server with one of the above-supported protocols without human interaction.

By installing Curl on Ubuntu 24.04, users gain access to a robust set of features that facilitate automated scripts for downloading files, managing API interactions, and performing site health checks. This article will explain different methods to install Curl on Ubuntu 24.04 based on supported content:

Let’s begin with the installation.

How to Install Curl on Ubuntu 24.04?

Developers and system administrators widely use curl for tasks such as API interaction, file download/upload, and web scraping. To install Curl on Ubuntu 24.04, follow these methods:

Let’s start with the default package manager.

Method 1: Install Curl on Ubuntu 24.04 Using APT

The easiest way to install Curl on Ubuntu 24.04 is to use the default package manager, apt. Let’s follow the below steps:

Step 1: Update the Packages List

First, update the packages index before installing curl on Ubuntu:

sudo apt update

Step 2: Install Curl

Now, install curl using the apt command with the “sudo” privileges. It installs the latest version of Curl available in the Ubuntu repositories:

sudo apt install curl

Step 3: Verify Curl Installation

After compilation, users can verify the installation by checking the Curl version:

curl --version

Remove/Uninstall Curl

To remove/uninstall curl from Ubuntu 24.04, use the “remove” option with the apt command:

sudo apt remove curl # Remove Curl Package Only

sudo apt purge curl # Remove Curl with Dependent Packages

sudo apt autoremove curl # Completely Remove Curl

That is all from the installation of the curl.

Method 2: Install Curl on Ubuntu 24.04 Using Source Code

Another method to install Curl on Ubuntu 24.04 is through the compilation from the source. This method allows users to install Curl (latest version) and customize its features and options. To install Curl from the source, follow the below steps:

Step 1: Update Package Lists

Begin by updating package lists with the apt command:

sudo apt update

Step 2: Install Dependencies

Next, install the necessary build dependencies such as “libssl-dev” and “zlib1g-dev” as below:c

sudo apt install build-essential libssl-dev zlib1g-dev

Step 3: Download Curl Source Code

Once the dependencies are in place, navigate to the official Curl website and download the latest source code tarball:

wget https://curl.se/download/curl-8.6.0.tar.gz

Step 4: Extract Downloaded File

Now, it’s time to extract the tarball with the “tar” command by mentioning “curl-*” or file name:

tar -xvf curl-*.tar.gz

Step 5: Configure Build Options

Next, change it to the extracted directory and configure the build options to ensure SSL support with the below commands:

cd curl-8.6.0

./configure --with-ssl

Step 6: Compile and Install Curl

Once the configuration is done, build the software to compile the source code:

make

Step 7: Install Curl

Finally, install curl on Ubuntu 24.04 with the help of the “install” command as below:

sudo make install

Step 8: Installed Curl Version

Finally, update the system library cache and check the Curl version using the “version” utility:

sudo ldconfig
curl --version

If users find an error of “bash: /usr/bin/curl: No such file or directory”, first, find the path where “curl” is installed and add it to the PATH variable as below:

which curl
export PATH=$PATH:/usr/local/bin/curl
source ~/.bashrc

In this way, curl has been installed on Ubuntu 24.04.

How to Use Curl on Ubuntu 24.04?

In the Ubuntu system, the Curl is a dynamic tool utilized for transferring data with URLs.

Its utility spans from simple file downloads to complex operations like HTTP POST, HTTP PUT, FTP uploads, SSL connections, proxy support, and more.

Once installed, users can use Curl to download files from the internet via the below syntax:

curl -O [URL]

where “[URL]” is the link to the file users wish to download. For more advanced usage, such as sending data with POST requests, use

curl -d "[data]" [URL]

Here, replacing “[data]” with the actual data users want to send and “[URL]” with the endpoint users are targeting.

Here are some examples of how to use curl in various scenarios:

Example 1: Retrieve the Content of a URL

To display the source code (HTML content) of a webpage, simply provide the URL to curl:

curl https://linuxgenie.net/

Retrieve Only HTTP Headers

Use the -I or –head option to fetch only the HTTP headers by mentioning the URL:

curl -I https://linuxgenie.net/

Example 2: Downloading a File

To download a file on Ubuntu 24.04, use “curl” with the “O” flag. It saves the file with the same name as on the server:

curl -O https://curl.se/download/curl-8.6.0.tar.gz

Download and Save Content to a File (Locally)

To download as well as save content to a file, utilize the –output or -o option. It saves the output of curl to a file locally:

curl http://linuxgenie.net -o output.txt

Download Multiple Files

Users can also utilize multiple -O options to download multiple files by specifying the URLs:

curl -O https://curl.se/download/curl-8.6.0.tar.gz -O https://curl.se/download/curl-8.5.0.tar.gz

Example 3: Resume an Interrupted Download

If the connection drops during a large file download, resume it using the -C – option:

curl -C - -O https://curl.se/download/curl-845.0.tar.gz

Follow Redirects

Use the –location or -L option to redirect, use the below command by specifying the URL:

curl -L https://linuxgenie.net/

Check HTTP Status

Retrieve the HTTP status code using the -I option:

curl -I https://linuxgenie.net/

Example 4: Set Maximum Transfer Rate

Users can also limit the download speed using the –limit-rate option. For instance, set the “1M” transfer limit as below:

curl --limit-rate 1M -O http://example.com/large-file.zip

Example 5: Making a POST Request with Data

For more advanced usage, such as sending data via a POST request, use the “curl” command with the “d” flag.

It sends the specified data to the server’s resource:

curl -d "param1=value1&param2=value2" -X POST https://linuxgenie.net//resource

Tip: Upload a File to an FTP Server

Users can also upload a file to an FTP server with the help of the curl command. It prompts Curl to upload the local file to the specified path on the FTP server using the provided credentials:

curl -T /path/to/local/file ftp://ftp.example.com/remote/path/ --user username:password

Remember to replace ‘example.com’ with your actual URL and provide the necessary parameters as per your requirements.

Conclusion

The Curl command in Ubuntu 24.04 is an ideal tool utilized for transferring data with URLs. To install Curl on Ubuntu 24.04, update the package list, and install Curl using the “sudo apt install curl” command. To install Curl on Ubuntu 24.04 from the official website, download the source code, resolve dependencies, compile the code, and install it onto the system.

To use Curl, type “curl” followed by the desired options and the URL of the resource users wish to interact with. For instance, “curl -O http://example.com/file.tar.gz” downloads the file from the specified URL. For more advanced usage, Curl offers options to send headers, upload data, or use different authentication methods.

Print Friendly, PDF & Email
Categories