4

I have 2 versions of curl installed on my system, one with http2 support.

I thought I could use which to point to the binary, but it doesn't seem to work the way I expect.

$ curl --http2 -I https://something.example.com
curl: (1) Unsupported protocol
$ which curl
/usr/local/bin/curl
$ /usr/local/bin/curl --http2 -I https://something.example.com
HTTP/2 200  
server: nginx/1.10.0 (Ubuntu)  
date: Thu, 08 Jun 2017 20:55:09 GMT  
content-length: 928  
last-modified: Thu, 08 Jun 2017 19:43:10 GMT  
cache-control: public, max-age=31536000  
accept-ranges: bytes  

which is pointing to my locally built binary /usr/local/bin/curl but the actual command is executing the package binary /usr/bin/curl

I don't have an alias for curl, so can someone please explain to me why this is so? And what command should I run to find the actual path to curl, which I happen to know is /usr/bin/curl

muru
  • 197,895
  • 55
  • 485
  • 740
Jeff Puckett
  • 1,741

1 Answers1

2

If you run:

echo $PATH

You are going to get something similar to:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

As you can see, /usr/local/bin has a higher priority, so bash will find your locally installed version of curl first and stop searching any more.

You can change this behavior by editing PATH environment variable, e.g (in .profile):

PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/sbin:/usr/local/bin
Ravexina
  • 55,668
  • 25
  • 164
  • 183