Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thesuhu/bccd43a4dc998e738d1f3578f34949ce to your computer and use it in GitHub Desktop.
Save thesuhu/bccd43a4dc998e738d1f3578f34949ce to your computer and use it in GitHub Desktop.
How to Build and Install Latest cURL Version CentOS

How to Build and Install Latest cURL Version on CentOS

# Written by The Suhu (2021).

# Tested on CentOS 7 and CentOS 8

Previously I've written about How to Build and Install Latest cURL Version on Ubuntu. In this article in this article explain how to build and install latest cURL version on CentOS.

The default cURL installed on the operating system may not be the latest version. if you want the latest version, then you need to build from the source. Let’s check the cURL version installed with the following command.

[thesuhu@centos-8-1 ~]$ curl --version
curl 7.61.1 (x86_64-redhat-linux-gnu) libcurl/7.61.1 OpenSSL/1.1.1g zlib/1.2.11 brotli/1.0.6 libidn2/2.2.0 libpsl/0
.20.2 (+libidn2/2.2.0) libssh/0.9.4/openssl/zlib nghttp2/1.33.0
Release-Date: 2018-09-05
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps 
telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz brotli TLS-SRP HTTP2 UnixSocke
ts HTTPS-proxy PSL 

Above shows the installed cURL version 7.61.0. While currently the latest version of cURL is 7.80.0. Go to https://curl.se/download/ to check the latest cURL version.

Download cURL latest version

Before we download the latest version of cURL, let’s update the system. It’s optional but I prefer to do this to keep the installed packages up to date.

sudo yum update -y

Install required packages.

sudo yum install wget gcc openssl-devel make -y

Download the latest cURL source. In this tutorial we will download 7.80.0 version.

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

Then extract the downloaded.

tar -xzvf curl-7.80.0.tar.gz

Building cURL

Go to the extracted directory of downloaded cURL source file.

cd curl-7.80.0

Now it’s time to build with configure command.

./configure --prefix=/usr/local --with-ssl

Make sure there are no errors from the above command execution. If there are no errors, finally we can install it with the make command.

make
sudo make install
sudo ldconfig

New version check

To make sure the new version is installed successfully, open a new session from terminal/ssh and run the command:

[thesuhu@centos-8-1 ~]$ curl --version
curl 7.80.0 (x86_64-pc-linux-gnu) libcurl/7.80.0 OpenSSL/1.1.1k-fips zlib/1.2.11
Release-Date: 2021-11-10
Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet 
tftp 
Features: alt-svc AsynchDNS HSTS HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL TLS-SRP UnixSockets

The cURL version should be 7.80.0.

The fast way

If you don't want to bother running commands one by one, you can create the script file below and run it.

#! /bin/bash

# Tested on CentOS 7 and CentOS 8
# Check the latest version at https://curl.se/download/
VERSION=7.80.0

cd ~
sudo yum update -y
sudo yum install wget gcc openssl-devel make -y
wget https://curl.haxx.se/download/curl-${VERSION}.tar.gz
tar -xzvf curl-${VERSION}.tar.gz 
rm -f curl-${VERSION}.tar.gz
cd curl-${VERSION}
./configure --prefix=/usr/local --with-ssl
make
sudo make install
sudo ldconfig
cd ~
rm -rf curl-${VERSION}

That's all and if you find it useful please star (⭐) & share.

@SiddharthPant
Copy link

Thanks for the precise instructions and the script at the end. It worked nicely and saved me from unnecessary headaches.

@thesuhu
Copy link
Author

thesuhu commented Jan 10, 2023

Thanks for the precise instructions and the script at the end. It worked nicely and saved me from unnecessary headaches.

You're welcome

@brynjellis
Copy link

Yes, thanks very much indeed! This is excellent! Just one thing, I presume there is nothing to stop one adding
yum remove wget gcc openssl-devel make -y
to the end of the script to tidy up, i.e. there are no runtime dependencies after the build and install?

@SiddharthPant
Copy link

Yes, thanks very much indeed! This is excellent! Just one thing, I presume there is nothing to stop one adding
yum remove wget gcc openssl-devel make -y
to the end of the script to tidy up, i.e. there are no runtime dependencies after the build and install?

On something like docker image, I think it makes sense to uninstall but on my work laptop usually, these are very common dependencies for everything out there so wouldn't uninstall. Also if gcc or make comes with the system, it might be a system dependency as well in which case it will brick your system.

@mattwmc
Copy link

mattwmc commented Sep 15, 2023

didn't work still says curl 7.29.0 is the version

@alireza-salehi
Copy link

still 7.29.0 , not working

@JamesTGrant
Copy link

JamesTGrant commented Dec 6, 2023

...didn't work still says curl 7.29.0 is the version

I can help you here!
You'll find the binary that was built in ./src/.libs/curl
Make the binary executable chmod +x ./src/.libs/curl
remove the old binary rm -f /usr/bin/curl
copy the new binary to the 'normal' location cp ./src/.libs/curl /usr/bin/curl
Now if you do curl --version you'll see the version you want!

@rafaelcaldastx
Copy link

...didn't work still says curl 7.29.0 is the version

I can help you here! You'll find the binary that was built in ./src/.libs/curl Make the binary executable chmod +x ./src/.libs/curl remove the old binary rm -f /usr/bin/curl copy the new binary to the 'normal' location cp ./src/.libs/curl /usr/bin/curl Now if you do curl --version you'll see the version you want!

That worked! Thanks mate 👊

@ZionMoore79
Copy link

ZionMoore79 commented May 7, 2024

...didn't work still says curl 7.29.0 is the version

I can help you here! You'll find the binary that was built in ./src/.libs/curl Make the binary executable chmod +x ./src/.libs/curl remove the old binary rm -f /usr/bin/curl copy the new binary to the 'normal' location cp ./src/.libs/curl /usr/bin/curl Now if you do curl --version you'll see the version you want!

Hello, I worked like you said.
When I typing line command in SSH: curl --version the it show:
curl 8.7.1 (x86_64-pc-linux-gnu) libcurl/8.7.1 OpenSSL/1.0.2k-fips zlib/1.2.7 brotli/1.0.9 zstd/1.5.5 nghttp2/1.33.0 libgsasl/1.8.0
Release-Date: 2024-03-27
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli gsasl HSTS HTTP2 HTTPS-proxy IPv6 Largefile libz NTLM SSL threadsafe UnixSockets zstd

=> But when I run php file with command:
phpinfo();

=> then it shows:
cURL support enabled
cURL Information 7.29.0

=> It means curl version is still 7.29.0

=> So how can I do to update it to lastest version (8.7.1)?

*Notes:

  • My PHP is 8.2
  • OS is Centos 7

Thanks!

@JamesTGrant
Copy link

Hi @ZionMoore79, just saw your message.
curl is compiled into PHP https://www.php.net/manual/en/curl.installation.php
So... you'll have to compile PHP from source
Hope that helps!

@ZionMoore79
Copy link

ZionMoore79 commented May 8, 2024

Hi @ZionMoore79, just saw your message. curl is compiled into PHP https://www.php.net/manual/en/curl.installation.php So... you'll have to compile PHP from source Hope that helps!
Hello, I had just compiled PHP with curl. So when I run phpinfo(); then curl version is still 7.9.0.


sudo yum update -y
sudo yum install wget gcc openssl-devel make -y
wget https://curl.se/download/curl-8.7.1.tar.gz
tar -xzvf curl-8.7.1.tar.gz
cd curl-8.7.1
./configure --prefix=/usr/local --with-ssl
./configure --with-curl=/usr/local
make
sudo make install
sudo ldconfig

=>./configure --with-curl=/usr/local this's command line to complied PHP with curl.

  • Note: /usr/local - this folder has lib and include folder
    So what's wrong!

@vasumahalingam
Copy link

Thanks for the instructions. I am still facing one minor problem. rpm qa still pointing to libcurl-7.61.1-34.el8.x86_64
curl-7.61.1-34.el8.x86_64 but I installed curl 8.7.0. Any suggestions on how to update the rpm info?

@JamesTGrant
Copy link

@vasumahalingam
I think you want to make your own curl rpm package. There are a couple of ways to do this and fortunately, lots of people have done this already.

  1. I've done this using rpmrebuild (https://rpmrebuild.sourceforge.net/). You can install rpmrebuild using yum from EPEL repo. Have a look at https://stackoverflow.com/questions/61316937/modify-rpm-using-rpmrebuild

  2. You can do this from source without requiring an existing RPM using a spec file similar to this:

rpmbuild -bb --define="dist .el7" --define "_topdir <directory>" \
            --define "_prefix <path to curl files>" my-curl.spec

Have a look at how the centos curl rpm spec is defined: https://git.centos.org/rpms/curl/blob/c7/f/SPECS/curl.spec
And have a search for 'how to build an RPM from source'

@3dom3k
Copy link

3dom3k commented Aug 13, 2024

I can confirm, that this guide (the guide of original poster "thesuhu") works on CentOS 6 too. Specifically, I have a 32 bit version, but I beleive that it does not matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment