How To

Install Curl on Ubuntu 18.04: Setup and Common Usage Examples

You follow a tutorial, run a command, and get: curl: command not found. It simply means curl is not installed on your system yet.

Curl is a command-line tool for transferring data to and from remote servers. It supports a wide range of protocols including HTTP, HTTPS, FTP, SFTP, and SCP. Developers use it to test REST APIs, automate file downloads in shell scripts, debug server headers, and interact with web services without opening a browser. It is powered by the libcurl library, which is embedded in thousands of programs across multiple languages.

On a fresh Ubuntu server or minimal desktop installation, curl may not be pre-installed. This guide shows you how to install curl on Ubuntu 18.04 and covers the most common use cases.

<strong>Prerequisite:</strong>&nbsp;You need sudo access.

Install Curl on Ubuntu

Curl is included in Ubuntu’s default repositories. Install it with:

bashsudo apt install curl

Verify the installation by running curl with no arguments:

bashcurl

You will see a short help prompt:

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

That output confirms curl is installed and available on your system.

Download Files with Curl

In its simplest form, curl fetches the content of a URL and prints it to your terminal. This prints the HTML source of the example.com homepage directly to the screen:

bashcurl https://example.com

To download a file and save it with a custom name, use the -o flag:

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

To save the file using its original filename from the server, use the uppercase -O flag:

bashcurl -O https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.0.5.tar.xz

If a download gets interrupted, resume it with the -C - flag instead of starting over from scratch:

bashcurl -C - -O https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.0.5.tar.xz

Other Common Curl Options

Fetch HTTP headers only

To inspect a server’s response headers without downloading the full page body, use the -I flag:

bashcurl -I https://www.ubuntu.com/

The output shows the response status code, content type, cache headers, and more. The status code on the first line (such as 200 OK301 Moved Permanently, or 404 Not Found) gives you a quick signal of how the server responded, without downloading any page content. This is useful for checking redirects, confirming SSL is active, or verifying caching configuration.

Follow redirects

By default, curl does not follow HTTP redirects. Add the -L flag to tell curl to follow any redirect it receives:

bashcurl -L https://example.com

Download from an FTP server

To download from a password-protected FTP server, pass the credentials with the -u flag:

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

Test a REST API endpoint

Curl is widely used to test APIs directly from the terminal. This example sends a POST request with a JSON body:

bashcurl -X POST https://api.example.com/data \     -H "Content-Type: application/json" \     -d '{"key": "value"}'

The -H flag adds a custom header, -X sets the HTTP method, and -d sends the request body.

Curl is now installed on your Ubuntu 18.04 system. For a complete list of available options, run curl --manual in your terminal or visit the official curl documentation. Leave a comment below if you run into any issues.

Cyber Defence

Recent Posts

Install Joomla on Ubuntu 18.04 with Apache: LAMP Stack Guide

Joomla is one of the most popular open-source content management systems in the world. It is…

2 hours ago

Install WordPress on Ubuntu 18.04 with Apache: LAMP Stack Guide

WordPress is the most popular open-source content management system in the world, powering over a quarter…

2 hours ago

Install Postman on Ubuntu 18.04: Snap Setup and First API Request

Postman is a complete API development environment used by developers at every stage of building APIs…

2 hours ago

Install VLC Media Player on Ubuntu 18.04: Snap Setup Guide

VLC is one of the most popular open-source multimedia players in the world, developed by the…

2 hours ago

Install Opera Web Browser on Ubuntu 18.04: Complete Setup Guide

Opera is one of the most popular cross-platform web browsers in the world, available on Windows,…

1 day ago

Install Gogs on Ubuntu 18.04: Self-Hosted Git Server Setup Guide

Gogs is a free, self-hosted Git service written in Go. It gives you a private GitHub-like…

1 day ago