Friday, 27 January 2017

How to install curl from source on Ubuntu


NOTE: curl has already been installed on a system via package manager:


$ which curl

/usr/bin/curl


/usr/bin directory contains user applications installed via package (distribution) manager.

Instructions


Go to curl download page and download the latest source code. At the time of writing, it was curl-7.52.1.tar.gz.


$ wget https://curl.haxx.se/download/curl-7.52.1.tar.gz

--2017-01-26 00:00:29-- https://curl.haxx.se/download/curl-7.52.1.tar.gz
Resolving curl.haxx.se (curl.haxx.se)... 2a00:1a28:1200:9::2, 80.67.6.50
Connecting to curl.haxx.se (curl.haxx.se)|2a00:1a28:1200:9::2|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3504621 (3.3M) [application/x-gzip]
Saving to: ‘curl-7.52.1.tar.gz’

curl-7.52.1.tar.gz 100%[===================>] 3.34M 265KB/s in 13s

2017-01-26 00:00:43 (260 KB/s) - ‘curl-7.52.1.tar.gz’ saved [3504621/3504621]



Unpack compressed file with tar:


$ tar -xvf curl-7.52.1.tar.gz

curl-7.52.1/
curl-7.52.1/projects/
curl-7.52.1/projects/README
curl-7.52.1/projects/checksrc.bat
(...)
curl-7.52.1/Makefile.am
curl-7.52.1/Makefile.in
curl-7.52.1/buildconf.bat



Meaning of used tar parameters:
-x = extract
-v = verbose
-f <archive_file>

Now perform standard Unix-style build & install steps (configure - make - make install).

configure verifies that compiler and all dependencies for build are present at the system and adjusts build configuration if necessary. It uses Makefile template file (Makefile.in) in order to create Makefile file which contains instructions for building and installation:


$ ./configure

checking whether to enable maintainer-specific portions of Makefiles... no
checking whether make supports nested variables... yes
(...)
configure: amending tests/server/Makefile
configure: amending tests/libtest/Makefile
configure: amending docs/examples/Makefile
configure: Configured to build curl/libcurl:

curl version: 7.52.1
Host setup: x86_64-pc-linux-gnu
Install prefix: /usr/local
Compiler: gcc
SSL support: no (--with-{ssl,gnutls,nss,polarssl,mbedtls,cyassl,axtls,winssl,darwinssl} )
SSH support: no (--with-libssh2)
zlib support: enabled
GSS-API support: no (--with-gssapi)
TLS-SRP support: no (--enable-tls-srp)
resolver: default (--enable-ares / --enable-threaded-resolver)
IPv6 support: enabled
Unix sockets support: enabled
IDN support: no (--with-{libidn2,winidn})
Build libcurl: Shared=yes, Static=yes
Built-in manual: enabled
--libcurl option: enabled (--disable-libcurl-option)
Verbose errors: enabled (--disable-verbose)
SSPI support: no (--enable-sspi)
ca cert bundle: /etc/ssl/certs/ca-certificates.crt
ca cert path: no
ca fallback: no
LDAP support: no (--enable-ldap / --with-ldap-lib / --with-lber-lib)
LDAPS support: no (--enable-ldaps)
RTSP support: enabled
RTMP support: no (--with-librtmp)
metalink support: no (--with-libmetalink)
PSL support: no (libpsl not found)
HTTP2 support: disabled (--with-nghttp2)
Protocols: DICT FILE FTP GOPHER HTTP IMAP POP3 RTSP SMTP TELNET TFTP



make executes build commands from Makefile and builds the application:


$ make

Making all in lib
make[1]: Entering directory '/home/bojan/Downloads/curl-7.52.1/lib'
make all-am
make[2]: Entering directory '/home/bojan/Downloads/curl-7.52.1/lib'
CC libcurl_la-file.lo
CC libcurl_la-timeval.lo
(...)
make[1]: Entering directory '/home/bojan/Downloads/curl-7.52.1'
make[1]: Nothing to be done for 'all-am'.
make[1]: Leaving directory '/home/bojan/Downloads/curl-7.52.1'



make install executes installation commands from Makefile. It copies binaries to a /usr/local/bin - a directory which contains locally built user applications (not those installed via package manager):


$ sudo make install

Making install in lib
make[1]: Entering directory '/home/bojan/Downloads/curl-7.52.1/lib'
make[2]: Entering directory '/home/bojan/Downloads/curl-7.52.1/lib'
/bin/mkdir -p '/usr/local/lib'
/bin/bash ../libtool --mode=install /usr/bin/install -c libcurl.la '/usr/local/lib'
(...)
make[1]: Entering directory '/home/bojan/Downloads/curl-7.52.1'
make[2]: Entering directory '/home/bojan/Downloads/curl-7.52.1'
/bin/mkdir -p '/usr/local/bin'
/usr/bin/install -c curl-config '/usr/local/bin'
/bin/mkdir -p '/usr/local/lib/pkgconfig'
/usr/bin/install -c -m 644 libcurl.pc '/usr/local/lib/pkgconfig'
(...)
/bin/mkdir -p '/usr/local/share/man/man1'
/usr/bin/install -c -m 644 curl.1 curl-config.1 '/usr/local/share/man/man1'
make[6]: Leaving directory '/home/bojan/Downloads/curl-7.52.1/docs'
make[5]: Leaving directory '/home/bojan/Downloads/curl-7.52.1/docs'
make[4]: Leaving directory '/home/bojan/Downloads/curl-7.52.1/docs'
make[3]: Leaving directory '/home/bojan/Downloads/curl-7.52.1'
make[2]: Leaving directory '/home/bojan/Downloads/curl-7.52.1'
make[1]: Leaving directory '/home/bojan/Downloads/curl-7.52.1'



We can verify that curl is indeed installed:


$ which curl

/usr/local/bin/curl



We can also verify its version, protocols and features this (custom) build supports:


$ curl --version
curl 7.52.1 (x86_64-pc-linux-gnu) libcurl/7.52.1 zlib/1.2.8
Protocols: dict file ftp gopher http imap pop3 rtsp smtp telnet tftp
Features: IPv6 Largefile libz UnixSockets



References:


The magic behind configure, make, make install
/usr/bin vs /usr/local/bin on Linux

Post a Comment