Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
share|improve this question
    
What shell are you using? (it would be bash unless you changed it) –  cg505 Mar 24 '13 at 20:28
    
I'm running ubuntu 12.04 and am using bash, $ echo $0 -bash. This is pretty much a fresh install I launched from a ubuntu 12.04 AMI cloud-images.ubuntu.com/precise/current –  user784637 Mar 24 '13 at 20:30
1  
Can you also post file $(which -a redis-cli)? –  arrange Mar 24 '13 at 20:33
    
file $(which -a 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 –  user784637 Mar 24 '13 at 20:35
    
... and file /usr/bin/redis-cli exists? Please post file /usr/bin/redis-cli and uname -a. –  arrange Mar 24 '13 at 20:48

2 Answers 2

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
share|improve this answer
    
This is what happens to me, and as this can easily happen: Dear Reader, this is probably what happens to you! –  Ramon Snir Oct 6 at 10:18

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.