hash -r or just starting a new shell usually fixes this problem.
If the file is actually gone, then the shell probably just still has it hashed.
First I suggest you verify that
/usr/local/bin/cpan really is gone:
ls -l /usr/local/bin/cpan
If there is something there, then you didn't fully uninstall. If there is nothing there, then you will get this message:
ls: cannot access '/usr/local/bin/cpan': No such file or directory
Assuming you got that message, but
bash is trying to run
/usr/local/bin/cpan when you type in
cpan and press Enter, the problem is most likely that
bash still has that path hashed. Rather than looking up where external commands are every time, shells typically hash their locations. So you can fix the problem by telling
bash to "rehash," by running:
Or just start a new shell.
If that doesn't work, check if it's an alias or shell function.
If the file is neither still present nor still hashed, then most likely
cpan is an alias or shell function that acts as a wrapper for
/usr/local/bin/cpan. To ascertain this, run:
type -a cpan
If it's an alias or shell function, that will show the definition. Then you can unset it with
unalias cpan if it's an alias, or
unset -f cpan if it's a shell function.
You will ultimately want to remove the definition from whatever startup script contains it. Usually it will be in the
.bashrc file in your home directory. Aliases are sometimes defined in
.bash_aliases. (Occasionally people define aliases and shell functions in
.bash_login, even though this is not a very good practice.)
If that doesn't work, consider how you're running
cpan or what shell you're in.
If the file is gone, not still hashed, not an alias or shell function, and
type -a doesn't reveal the problem, then most likely you are either (a) not running
cpan directly through that command, or (b) using a shell other than
bash. In the former case there is no way to answer without further details.
The latter case seems unlikely since your shell calls itself
bash, though every once in a while someone ill-advisedly makes a symlink called
bash to a shell that isn't (which isn't advisable). The truth is, I'm mainly mentioning this for the benefit of other readers. Based on that message, you're almost certainly using
However, in case you're not or might not be, run
echo "$BASH_VERSION" to see if you're running
bash--this should be unset in other shells--and
echo "$SHELL" to see what your default shell is. Rehashing works differently--or is at least achieved differently--in other shells.
Some other Bourne-style shells, like
zsh, have a
rehash command that you would run instead of
hash -r. That is also how you would cause rehashing to occur in