After a fresh install of Rails using Gem recently, I was surprised to see the following message:
-bash: rails: command not found
After rebooting just to make sure, the issue persisted. I am not sure why but it seems that the binaries were not added to my PATH variable (I am seeing this for the first time while using Majaro Linux).
To resolve, follow the steps below:
1. Find location of Gem binaries:
Open up a terminal and type the following command:
In the output, find the part with "GEM PATHS". For mine I get the output below. We are interested in the second entry (/home/renan/.gem/ruby/2.5.0). This location contains a subdirectory named "bin", which is what we need to add to PATH. Obviously, this location will look different depending on your OS, ruby version, etc. But make a note of this location, which we will use in the next step.
- GEM PATHS: - /usr/lib/ruby/gems/2.5.0 - /home/renan/.gem/ruby/2.5.0
2. Add Location to .bashrc:
In your terminal, type the following command:
echo "PATH=$PATH:<path copied in step above>/bin" > ~/.bashrc
In my case for example, I have:
echo "PATH=$PATH:/home/renan/.gem/ruby/2.5.0/bin" > ~/.bashrc
3 Reboot and Try Again
If your terminal is setup as a "login shell", then all you need to do is close and reopen the terminal. Otherwise, you will need to logoff/log back in to your OS. After that, opem your terminal and try again. I hope that this was able to resolve your issue :-)