I installed cowsay, to try fun ways to learn linux commands. Using:

sudo apt install cowsay

And when I tried using it, like this: cowsay helloworld It did not work, I got bash: cowsay: command not found

I couldn't understand why. After trying to look it up, I realized that I could make it work by typing the full path:

/usr/games/cowsay helloworld and it worked. (edited to correct user to usr)

Is there a way to make it work from anywhere by just typing cowsay helloworld, without the full path?

  • 1
    Could you post edit it, with the output of echo $PATH? – schrodigerscatcuriosity May 1 at 18:39
  • 2
    Which distribution is it? It works on Debian... Also, it would help to know how it did not work. You probably had some error message. – Eduardo Trápani May 1 at 18:46
  • 1
    Are you sure you used /user/games/cowsay and not /usr/games/cowsay? – Arkadiusz Drabczyk May 1 at 18:59
  • You can prepend the program to the paths searched with echo '$PATH=/usr/bin/cowysay:$PATH' >> ~/.bashrc. Make sure that your shell is bash first evaluating echo $SHELL. – Max1 May 1 at 19:30
  • How about using hash -r, assuming you're in Bash? Perhaps you attempted to run cowsay before?! ... also, /usr/games simply may not be in your PATH as was pointed out. – 0xC0000022L May 1 at 21:18

You need to add /usr/games to your $PATH variable.

To do so (on a permanent basis):

  1. Edit your .bashrc file, for example, by typing vim ~/.bashrc.
  2. Add the following line to the .bashrc file and save it

  3. Type source ~/.bashrc to make it take effect.

| improve this answer | |

Your Answer

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

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