DEV Community

Kamal Mustafa
Kamal Mustafa

Posted on

Dealing with command not found on linux/osx

Most of us who familiar with linux or osx already knew the PATH environment variable that being used by shell program to find the where is the command we type. Every time we type command such as virtualemv and got error like:-

bash: virtualemv: command not found
Enter fullscreen mode Exit fullscreen mode

We will check the PATH properly set. But with all the environment manager for different kind of language we use - rbenv, rvm, pyenv, conda, nix etc, they all append or prepend some paths to the PATH variable to make their magic work. And it all got messy after a while.

When we're not sure where certain command come from, usually we'll use the which command:-

which virtualenv
Enter fullscreen mode Exit fullscreen mode

The problem with which is that it's an external program, it only look for command within the PATH, it's not really a representative of what the shell will actually execute. The built-in shell command type or hash will be more accurate to report what command actually executed when you type the command in your shell.

Sometimes you got a mysterious command not found even which or type return a path to the command. This could be because the command has been pointed to a new executable but the shell internal hash still pointing to the old one. If using bash, you can type bash -r to rehash all the commands cache.

More info on this Stackoverflow question.

Top comments (0)