Ruby Command Not Recognized After Installing It with Rvm
I Followed This Tutorial to Install Ruby with Rvm: the Problem Is That Everytime That I Log In, the Ruby Installation Is Not Recognized, for Example If I Try...
I followed this tutorial to install ruby with rvm:
The problem is that everytime that I log in, the ruby installation is not recognized, for example if I try executing a ruby script with the "ruby" command this is what I get:
To make it be recognized I have to run this command:
source ~/.rvm/scripts/rvm
But every time I login I have to do it again.
3 Answers
What went wrong?
During installation, rvm puts two lines (first one is a comment though) in ~/.bash_profile file to help bash recognize ruby binaries. But the problem is Ubuntu's bash ignores this file. As a result, it doesn't know that you already installed ruby and prompts you to install ruby!
The problem can be solved in two different way.
Solution 1: Using ~/.bashrc file
Open your ~/.bashrc file and put these two lines (or last one) there.
### Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Solution 2: Make the regular shell session as login shell
Or you can turn on your virtual terminal's preference to consider the shell as Login Shell. The settings can be found in -
Gnome Terminal: Menu > Edit > Profile Preference > Command Tab > Run command as a login shell
Mate Terminal: Menu > Edit > Profile Preference > Title & Command Tab > Run command as a login shell
Xfce4 Terminal: Menu > Edit > Preference > General Tab > Run command as login shell
Either one will do the job.
Another solution could be installing Ruby in System using Ubuntu's repository. But that defeats the purpose of using rvm at first place.
This will install old version of ruby (1.9) currently existing in Ubuntu repos. You might want to check installation from source
Download ruby tar from here and then run:
$ tar -xf ruby-your-downloaded-package
$ cd ruby_extracted_directory
$ ./configure
$ make
$ sudo make install
In some cases you will need to realod bash by typing:
$ bash