How to install curl on FreeBSD using pkg command

I am running FreeBSD 12 at AWS as EC2 VM. I am trying to run the curl command from FreeBSD Unix csh/tcsh/ksh/bash shell but getting the following error:
curl: Command not found.
How do I fix this on a FreeBSD Unix version 10/11/12/13?

The curl command is a tool to download or transfer files/data from or to a server using FTP, HTTP, HTTPS, SCP, SFTP, SMB, and other supported protocols on FreeBSD, Linux, or Unix-like system. It provides many more functions that are useful for debugging CDNs, networking, web-server issues. We can upload files and much more. This quick guide explains how to install the curl command on FreeBSD either using the pkg command or ports.

Installing Curl on FreeBSD

  1. Open the terminal application and then type the following BSD commands.
  2. For remote FreeBSD server use the ssh command: ssh vivek@freebsd-ec2-server-ip
  3. Update system, run: sudo pkg update && sudo pkg upgrade
  4. Install curl on Debian, execute: sudo pkg install curl
  5. Test curl CLI

How to install curl on FreeBSD version 10/11/12/13

First, apply security updates for your FreeBSD box using pkg/freebsd-update:
$ sudo pkg update
$ sudo pkg upgrae

Next type the following command to install curl on FreeBSD:
$ sudo pkg install curl
OR use the FreeBSD ports collection:
# cd /usr/ports/ftp/curl/
# make install clean
# rehash

Sample outputs from the pkg:

 Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 3 package(s) will be affected (of 0 checked):
 
New packages to be INSTALLED:
	ca_root_nss: 3.58
	curl: 7.74.0
	libnghttp2: 1.41.0
 
Number of packages to be installed: 3
 
The process will require 5 MiB more space.
2 MiB to be downloaded.
 
Proceed with this action? [y/N]: y
[1/3] Fetching curl-7.74.0.txz: 100%    1 MiB 449.9kB/s    00:03    
[2/3] Fetching libnghttp2-1.41.0.txz: 100%  116 KiB 118.8kB/s    00:01    
[3/3] Fetching ca_root_nss-3.58.txz: 100%  285 KiB 291.5kB/s    00:01    
Checking integrity... done (0 conflicting)
[1/3] Installing libnghttp2-1.41.0...
[1/3] Extracting libnghttp2-1.41.0: 100%
[2/3] Installing ca_root_nss-3.58...
[2/3] Extracting ca_root_nss-3.58: 100%
[3/3] Installing curl-7.74.0...
[3/3] Extracting curl-7.74.0: 100%
=====
Message from ca_root_nss-3.58:
 
--
FreeBSD does not, and can not warrant that the certification authorities
whose certificates are included in this package have in any way been
audited for trustworthiness or RFC 3647 compliance.
 
Assessment and verification of trust is the complete responsibility of the
system administrator.
 
 
This package installs symlinks to support root certificates discovery by
default for software that uses OpenSSL.
 
This enables SSL Certificate Verification by client software without manual
intervention.
 
If you prefer to do this manually, replace the following symlinks with
either an empty file or your site-local certificate bundle.
 
  * /etc/ssl/cert.pem
  * /usr/local/etc/ssl/cert.pem
  * /usr/local/openssl/cert.pem

Showing curl version

For verification purpose type the following to see curl version installed on your FreeBSD cloud server:
curl --version
Report from my personal box:

curl 7.74.0 (amd64-portbld-freebsd12.1) libcurl/7.74.0 OpenSSL/1.1.1h zlib/1.2.11 nghttp2/1.41.0
Release-Date: 2020-12-09
Protocols: dict file ftp ftps gopher http https imap imaps mqtt pop3 pop3s rtsp smtp smtps telnet tftp 
Features: alt-svc AsynchDNS GSS-API HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz NTLM NTLM_WB SPNEGO SSL TLS-SRP UnixSockets

It seems I am using curl version 7.74.0.

Basic curl command usage

Once installed the curl on FreeBSD desktop, you can use it as follows to see the headers for given domain:
$ curl -I https://www.nixcraft.com
Headers for forum:

HTTP/2 200 
server: nginx
date: Sat, 02 Jan 2021 19:42:32 GMT
content-type: text/html; charset=utf-8
vary: Accept-Encoding
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-download-options: noopen
x-permitted-cross-domain-policies: none
referrer-policy: strict-origin-when-cross-origin
x-discourse-route: list/latest
cache-control: no-cache, no-store
content-security-policy: base-uri 'none'; object-src 'none'; script-src https://www.nixcraft.com/logs/ https://www.nixcraft.com/sidekiq/ https://www.nixcraft.com/mini-profiler-resources/ https://www.nixcraft.com/assets/ https://www.nixcraft.com/brotli_asset/ https://www.nixcraft.com/extra-locales/ https://www.nixcraft.com/highlight-js/ https://www.nixcraft.com/javascripts/ https://www.nixcraft.com/plugins/ https://www.nixcraft.com/theme-javascripts/ https://www.nixcraft.com/svg-sprite/ 'report-sample' https://www.google-analytics.com/analytics.js https: 'unsafe-inline'; worker-src 'self' https://www.nixcraft.com/assets/ https://www.nixcraft.com/brotli_asset/ https://www.nixcraft.com/javascripts/ https://www.nixcraft.com/plugins/; report-uri https://www.nixcraft.com/csp_reports
x-request-id: 5bf6bb22-0855-4550-916f-6a25075a0380
x-runtime: 0.118926
strict-transport-security: max-age=3153600

We can download a file from a server using curl itself:
curl -o output.file http://server1.cyberciti.biz/foo.bar.txt
You can resume broken download with the curl command as follows:
curl -L -O -C - http://ftp.ussg.iu.edu/linux/centos/latest/isos/file.iso

Getting more help on curl

Type the following man command:
man curl
OR
curl --help

Conclusion

And there you have it. See:


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @ webmaster@cyberciti.biz