How do I use homebrew less instead of system less?
Solution 1:
This might be due to bash's hash table of commands in PATH
still using the old value. Remove the hash of less
, or clear the hash, so that bash re-searches PATH
:
hash -d less
# or, hash -r
You can also manually add a path to the table:
hash -p /usr/local/bin/less less
From the Bash manual (emphasis mine):
If the name is neither a shell function nor a builtin, and contains no slashes, Bash searches each element of
$PATH
for a directory containing an executable file by that name. Bash uses a hash table to remember the full pathnames of executable files to avoid multiplePATH
searches (see the description ofhash
in Bourne Shell Builtins). A full search of the directories in$PATH
is performed only if the command is not found in the hash table.
Solution 2:
If homebrew is correctly installed /usr/local/bin/
is checked before /usr/bin/
. Check this with echo $PATH
, this will show you the path's the OS is trying to find the command you entered and it is trying them in the order that is shown.
A little fancier
using the bash shell:
echo $PATH | awk '{ n = split($0, paths, ":"); for (i=0; ++i <= n;) print i, paths[i] }'
(using the fish shell):
echo $PATH | awk '{ n = split($0, paths, " "); for (i=0; ++i <= n;) print i, paths[i] }'
This will show an numbered list of the path's tried. Mine shows
1 /Users/peter/.gem/ruby/2.0.0/bin
2 /usr/local/sbin
3 /usr/local/bin
4 /usr/bin
5 /bin
6 /usr/sbin
7 /sbin
8 /Library/TeX/texbin
The system will traverse the directories in the above order looking for commands, in your case less
. If it's not in the first one, it will try the next one until it runs out of options and throw up an error.
So if your echo $PATH
shows similar results as mine you are using the homebrew version of less.