Search code examples
linuxbashlinuxbrew

How to change default directory for a command in Bash?


Firstly, I am new to Linux so excuse me if any terminology is wrong; I'll try to phrase the problem as competently as possible.

I have installed Ruby (2.4.0) via Linuxbrew. The ruby command works fine; it installed correctly. However, when I try to use the gem command (which Ruby should have installed) I receive this error: bash: /usr/bin/gem: No such file or directory

Now, because I installed this with Linuxbrew I know that this directory isn't correct. For example:

result of which gem : /home/me/.linuxbrew/bin/gem

result of which ruby : /home/me/.linuxbrew/bin/ruby

Therefore, it seems gem is installed but the gem command isn't linked to the correct path. I assume I need to direct the gem command to the path of which gem as opposed to /usr/bin/gem that bash is saying doesn't exist. How would I go about changing this? I tried in vain to change the bash_profile but I'm not sure what to do.

Again, excuse me if ruby and gem are not referred to as commands and if the problem isn't the "default directory" as stated in the title. I wasn't sure how to label it.

EDIT/TL;DR:

Basically, how can I make gem execute this: /home/me/.linuxbrew/bin/gem instead of looking for the program in /usr/bin/gem?


Solution

  • To answer my own question-

    As I had previously installed and uninstalled Ruby via apt-get instead of Linuxbrew in the same Terminal window, Bash was looking for gem in usr/bin as opposed to the path specified in my bash_profile to Linuxbrew.

    Therefore, Stian's answer above with hash -r would also work, I am sure.