How to Install curl on Ubuntu: Beginner-Friendly Guide Using apt and snap

1. Beginner’s Guide: How to Install curl on Ubuntu (apt & snap)

What is curl?

curl is an open-source tool that allows you to transfer data from the command line. It supports many protocols such as HTTP, HTTPS, and FTP, making it useful for various purposes including sending API requests and downloading files.

Benefits of Using curl on Ubuntu

Ubuntu may not have curl installed by default. However, since curl is required for downloading software and performing API operations, installing it early is highly useful. Additionally, curl can be executed with simple commands and is suitable for automation in scripts.

2. Method ①: Install curl Using apt

What is apt?

apt (Advanced Package Tool) is the package management system used in Ubuntu. It allows you to install, update, and remove software from Ubuntu’s official repository. The official repository provides a stable version of curl.

Steps to Install curl with apt

  1. Update the package list
   sudo apt update
  1. Install curl
   sudo apt install curl
  1. Verify the installation
   curl --version

Pros and Cons of Installing with apt

ProsCons
High stability because it is provided through the official Ubuntu repositoryThe available version may not be the latest
Security updates are applied automaticallyCertain features may be limited depending on the version

3. Method ②: Install curl Using snap

What is snap?

snap is a newer package management system available for Ubuntu and other Linux distributions. snap packages manage dependencies independently, making them less affected by system version differences.

Steps to Install curl with snap

  1. Check whether snap is enabled
   snap --version
  1. Install curl using snap
   sudo snap install curl
  1. Check the snap version of curl
   curl --version

Pros and Cons of Installing with snap

ProsCons
Latest version is usually availableRequires snap environment (not installed by default)
Less affected by other system componentsMay take longer to start

4. Basic Usage of curl

Once curl is installed, try the basic commands below.

Retrieve a Web Page

This command retrieves the HTML data of the specified URL:

curl https://example.com

Download a File

To download a file, use the -O option:

curl -O https://example.com/sample.txt

Send an API Request

Use the -X option when sending an API request:

curl -X GET https://api.example.com/data

To obtain data in JSON format with headers specified:

curl -X GET https://api.example.com/data -H "Content-Type: application/json"

5. Troubleshooting curl Installation Issues

curl: command not found Error

Solution:

  • Check whether curl is installed:
  which curl
  • If not installed, reinstall using sudo apt install curl.

Could not resolve host Error

Solution:

  • Check network connectivity and DNS settings.
  • Verify connection using ping google.com.

If the Version is Outdated

Solution:

  • If you need the latest version, install the snap package.

6. FAQ

Q1: How do I update curl to the latest version?

A1: Wait for the Ubuntu official repository to update, or install the snap version.

Q2: What is the difference between curl and wget?

A2:

  • curl: Supports various data transmission operations including API requests.
  • wget: Primarily specialized for downloading files.

Q3: Can curl send HTTPS requests?

A3: Yes, curl supports HTTPS. You can disable certificate checks using the -k option.

7. Summary

This article explained how to install curl on Ubuntu using apt or snap, how to use basic curl commands, and how to troubleshoot common errors.

Main Takeaways

✅ curl may not be installed by default on Ubuntu
✅ apt is the standard installation method, but snap provides newer versions
✅ curl is useful for API requests and downloading files
✅ Check error messages carefully and apply the appropriate fix

curl is an extremely useful tool when working with Ubuntu, so installing it in advance will be beneficial.