Or little computing tricks and hacks
rvm and the gnome-terminal
August 25, 2013Posted by on
I’m in a new project: learning Ruby and Ruby on Rails. Ruby is a very pretty language. I highly recommend the codeacademy tutorials.
For Rails I started the book by Michael Hartl. I am now just installing Rails and there is a lot I have to go through.
I’m explaining here a problem I came across after installation when running the rvm. Actually when changing terminals. All of a sudden I could not even run Rails, even though I had already ran the server. (I had decided that the location of my first_app was not satisfactory when I was about to create a repository in GitHub.) The explanations of the topic are around this section.
When attempting to run
rvm use 2.0.0@railstutorial_rails_4_0 --default
the following scary message was displayed:
RVM is not a function, selecting rubies with ‘rvm use …’ will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash –login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for a example.
Luckily that link had the answer: when the gnome-terminal is not run as a login shell, not all of the right bash files are sourced. In that site, it is very well explained how to add the Run command as login shell to the Profile Preferences of the gnome terminal profile in use. (Full answer is here.)
The explanation of the problem is as follows:
- When you login graphically to your system it will read ~/.profile so you put there settings like LANG which are important for graphical applications
- When you open a terminal (except Gnome-terminal & Screen) you open a login shell which sources ~/.bash_profile
- When you execute commands in non login shell, it will execute ~/.bashrc
Added note 26 August 2013
I have decided to go back to the default setting: opening a gnome-terminal as a non-login shell. If I need to run rvm in a particular terminal, I’ll just open a new session in the terminal as follows:
Added note 30 August 2013
Running bash -l was not enough, althugh necessary.
The best solution is to include a .rvmrc file a the root of the application with a line indicating the gemset in use for that app: