Why isn't ubuntu checking the correct directory in the $PATH variable?

I'm trying to run a program redis-cli

$ ls -lh /usr/local/bin/ | grep redis
-rwxr-xr-x 1 root root 4.2M Mar 24 19:49 redis-cli
-rwxr-xr-x 1 root root 5.6M Mar 24 19:49 redis-server
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

If the program redis-cli exists in the directory /usr/local/bin and that directory is in my path variable, why do I get the following error?

$ redis-cli
-bash: /usr/bin/redis-cli: No such file or directory

EDIT

$ /usr/local/bin/redis-cli
redis 127.0.0.1:6379>
$ redis-cli
-bash: /usr/bin/redis-cli: No such file or directory
$ file /usr/local/bin/redis-cli
/usr/local/bin/redis-cli: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x3715af7983c534d902d8dc627f9b0f1b4c8b8e80, not stripped
8

2 Answers

Chances are there used to be a redis-cli in /usr/bin/redis-cli which has now been deleted.

Bash maintains an internal hash of executables on your path which hasn't been updated. If you encounter this problem again, rehash it and it will work.

hash redis-cli
1

It kind of looks like you have an alias or a shell function with that name; I believe both of those would bypass your $PATH and be hidden from 'which'.

To check for an alias:

alias redis-cli

To delete an alias if you find one:

unalias redis-cli

To check for a function:

declare -f redis-cli

To delete a function if you find one:

unset -f redis-cli

If one of these does turn out to be the problem, then those commands will only help until the end of that terminal session, and you would have to re-run them again next time. You'll want to check your .bashrc and .profile to see if there are any rogue commands in there that mention redis-cli. If that doesn't work, they may be somewhere in /etc.

grep redis-cli /etc

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like