How to set default Ruby version with RVM? - ruby-on-rails

Ubuntu 11.
I do the following:
$ rvm --default use 1.9.2
and I get:
Using /home/md/.rvm/gems/ruby-1.9.2-p180
so that is good.
but when I now open a new terminal window I still get:
$ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]

If you put the RVM source line in your bashrc (in order to ensure that non-interactive shells have access to RVM), you will need to source .bashrc from your .bash_profile with the following as the last lines in your .bash_profile
if [ -f "$HOME/.bashrc" ]; then
source $HOME/.bashrc
fi
This pre-supposes that you have
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
in your $HOME/.bashrc. This is a good way to ensure that both interactive/login and non-interactive shells are able to find and load RVM correctly. Multi-User installs accomplish the same thing via the /etc/profile.d/rvm.sh file.
After that, you should have no problems defining a default Ruby to use via
rvm 1.9.2 --default
or
rvm use 1.9.2#mygemset --default
Its better to define a default gemset to use so as not to pollute your 'default' or 'global' gemsets.
If you are using non-interactive shells, be aware that they genereally operate in SH-compatibility mode which then requires you to set
BASH_ENV="$HOME/.bashrc"
in your $HOME/.profile in order you load RVM, or to set that within your script directly. The reason for this is that when bash is operating in SH mode it does not directly load .bash_profile or .bashrc as SH doesn't use those files, and bash is attempting to mimic the loading and execution process of the SH shell.

do an "rvm list" to see which Ruby versions you have installed.
then do this if you want to change the version only in one terminal session:
rvm use 1.8.7
if you want to select the default version for this user account, do this:
rvm use --default 1.9.2
See:
rvm use --help
See also this RailsCast:
http://railscasts.com/episodes/200-rails-3-beta-and-rvm
http://beginrescueend.com/

Late to party - anyway.
You did correctly set the default ruby version: rvm --default use 1.9.2
However, you need to update your Gemfile to the target ruby, because RVM references that file to select the working ruby version when you open terminal , that's why it reverted to the previous ruby version.

To Change the Default Version of ruby:
In Ubuntu
Go to default Terminal of Ubuntu and then follow the instructions:
1) Edit -> Profile Preferences
2) Select "Title and Command"
3) check "Run command as a login shell"
4) restart terminal
And after that run this command:
rvm --default use 2.2.4#gemset_name

Related

How can I change Ruby to version 1.9.3 (again) with RVM?

I used to work with Ruby version 1.9.3 on Ubuntu and made an update that probably screwed my bash profile and I need help to turn it back rather than using version 1.8.7. Right now rails s opens the server with Ruby 1.8.7 and I get errors because of the newer syntax I use in my app.
.bash_profile:
cat ~/.bash_profile
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
which rails:
/usr/local/bin/rails
which ruby:
/usr/bin/ruby
ruby -v:
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]
rvm list:
rvm rubies
=* ruby-1.9.3-p194 [ i686 ]
# => - current
# =* - current && default
# * - default
rvm use 1.9.3:
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.
You are not in the login shell. To enter the login shell try this command:
/bin/bash --login
After that you will be able to use RVM to select Ruby.
Also, there is permanent way, that you won't have to write this line everytime you open your terminal.
Try this:
Edit menu -> Profile Preferences
A dialog will appear, now select Run command in login shell.
After that, whenever you open your terminal, you will enter into the login shell, and you will be able to use RVM.
There is another way, you can write /bin/bash --login in your .bash_profile which will load every time when you reboot.

RVM can not change gemset

Before I installed MySQL and restart my computer, my RVM works well.
If I type
rvm gemset use rails
It will show:
Using ruby-1.9.3-p194 with gemset rails
and then I type:
rvm gemset name
It shows:
rails
which is correct.
However, after I restart my computer, something strange happens.
Firstly, the system cannot find the command 'rvm', so I modified by ~/.bash_profile:
export PATH=/usr/local/mysql/bin:/Users/hanxu/.rvm/bin/:$PATH
Above is the content of my .bash_profile
Then rvm works.
Then I type:
rvm gemset use rails
It seems running well and shows:
Using ruby-1.9.3-p194 with gemset rails
However, when I examine it by asking rvm gemset name, it turns to be:
/Users/hanxu/.rvm/gems/ruby-1.9.3-p194
which is my default gemset, rather than "rails".
No matter how I set gemset, it always change to the default setting.
Can anyone tell me what's the problam?
Are you using an .rvmrc file?
https://rvm.io/workflow/rvmrc/
Your RVM installation is most likely incomplete. Look for this string in your .profile / .bashrc / .zshrc or whatever else you might be using
[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm
This command checks for existence of $HOME/.rvm/scripts/rvm and, if found, loads it into the shell. This effectively loads the RVM. So, if you don't find this command, add it and open a new terminal window, RVM should be there.
rvm has a command to fix sourcing:
rvm get stable --auto
the auto switch will update your *rc files, then it should be enough to open new terminal and it should be all fine.
Use this command to switch gemset.
rvm use <ruby version>#<gemset name> --create
This command will switch rvm to given gemset and create it, if it does not exist.
In my case, I needed to add the user to the rvm group before I could use rvm.

Can't seem to "use" the RVM Ruby install

I'm getting this error when I try to invoke rails, rails -v or rails -c:
/usr/lib/ruby/site_ruby/1.8/rubygems.rb:779:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError)
from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:214:in `activate'
from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:1082:in `gem'
from /usr/bin/rails:18
I installed RVM, used it to install Ruby 1.9.3, and switched to it rvm use 1.9.3 --default.
When I ruby -v:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
I also gem install rails --no-rdoc --no-ri and checked...ls ~/ruby/gems/gems/:
actionmailer-3.2.8/ journey-1.0.4/ rake-0.9.2.2/
actionpack-3.2.8/ json-1.7.5/ rdoc-3.12/
activemodel-3.2.8/ mail-2.4.4/ rubygems-bundler-1.0.7/
activerecord-3.2.8/ mime-types-1.19/ rvm-1.11.3.5/
activeresource-3.2.8/ multi_json-1.3.6/ sprockets-2.1.3/
activesupport-3.2.8/ polyglot-0.3.3/ sprockets-2.4.5/
arel-3.0.2/ rack-1.4.1/ thor-0.16.0/
builder-3.0.0/ rack-cache-1.2/ tilt-1.3.3/
bundler-1.1.5/ rack-ssl-1.3.2/ treetop-1.4.10/
erubis-2.7.0/ rack-test-0.6.1/ tzinfo-0.3.33/
hike-1.2.1/ rails-3.2.8/
i18n-0.6.0/ railties-3.2.8/
And if I echo $GEM_PATH:
/home/flackend/.rvm/gems/ruby-1.9.3-p194:/home/flackend/.rvm/gems/ruby-1.9.3-p194#global
echo $PATH:
/home/flackend/.rvm/gems/ruby-1.9.3-p194/bin:/home/flackend/.rvm/gems/ruby-1.9.3-p194#global/bin:/home/flackend/.rvm/rubies/ruby-1.9.3-p194/bin:/home/flackend/.rvm/bin:/usr/local/jdk/bin:/home/flackend/perl5/bin:/usr/kerberos/bin:/usr/lib/courier-imap/bin:/usr/lib64/ccache:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/X11R6/bin:/home/flackend/.rvm/bin:/home/flackend/bin
cat ~/.bashrc:
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
cat ~/.bash_profile:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
So somewhere something has a path that says to look at the system Ruby install. Any ideas? Thanks!
EDIT
Okay, also, If i switch back to the system Ruby, rvm use system, and rails -v, I get:
Rails 2.3.8
So I have no idea at all what this error is indicating.
You have not completed rvm installation. You need add ~/.rvm bin paths before /usr/bin by command in .bashrc:
[[ -s "/Users/pftg/.rvm/scripts/rvm" ]] && source "/Users/pftg/.rvm/scripts/rvm".
To test just check $PATH env. Should be similar to:
/.../.rvm/gems/ruby-1.9.3-p125#global/bin:/.../.rvm/rubies/ruby-1.9.3-p125/bin:/.../.rvm/bin:/usr/local/bin
If you installed everything ruby as well as rails means, you may need to select the 'Run command as login shell' checkbox by doing following,
Open terminal
Go to Edit tab, then select Profile Preferences from the menu item.
The Profile Preferences window should be displayed, then select Title and Command tab.
Then select the checkbox Run command as a login shell.
I just used RVM to create a "gemset", switched to it, and tried installing Rails again and it works now.
https://rvm.io/gemsets/
I'm not sure why that fixed it or why it wasn't working before. I like when things work, but I would rather have figured out why it wasn't working with the #global gemset.
Thanks for all your help!
I had the exact symptoms described above as well and was stuck on this problem for quite some time (the ruby environment and dependencies are a horrible mess). I can't say I'm out of the woods yet but at least I'm picking up the correct version of rails now and gotten past this error.
I believe the real issue here is actually to do with zlib. It seems that it's a crucial component to separate your system version of ruby (v1.8 likely install via yum/apt-get) with the other versions or Ruby you need (installed via rvm) for other projects.
If you do not have zlib installed, or rvm is not using it correctly, then sometimes you will pick up the system ruby/rails and all sorts of strange errors occur.
If you DO have zlib installed (yum/apt-get install zlib) then the trick I discovered was that I specifically had to tell rvm which version of zlib to use when installing ruby.
rvm install 1.9.3 --with-zlib-dir=$rvm_path/usr

rvm not defaulting to newer version of ruby

I am using ruby on rails on Ubuntu 11.10. Ruby 1.8.7 works fine but I cannot get rvm to work with 1.9.3 or any other version.
When I run rvm reload, rvm list or rvm info, I get the following message:
bash: /usr/bin/rvm: No such file or directory
I have Ruby 1.9.3 installed via rvm and when I change the default it doesn't give me an error. But then when I check the ruby -v it defaults back to 1.8.7.
Also, when I check which ruby it shows the following:
/usr/local/bin/ruby
My guess is that it has something to do with the bash file. What do you suggest?
I am guessing that it isn't even installing it correctly.
This is what happens:
I type the following into the prompt:
bash < <(curl -sk https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
And it outputs:
ERROR: Unable to checkout branch .
Are you following the installation instructions from the rvm site?
http://beginrescueend.com/rvm/install/
If you are then look at section 2 about the shell again.
specifically this command that they tell you to run :-)
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
remember to reload or restart your shell after running that command.
run the command
source /usr/local/rvm/scripts/rvm
and then
type rvm | head -1
you should get output -
rvm is a function.
And after that run
rvm use rvm use 2.0.0 --default

Setting the RVM path?

I installed RVM, Ruby 1.9.2 and Rails 3.0.9 on Lion which works fine. Only problem is, after I close the terminal I need to execute this:
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
for it to pick up RVM.I then need to make RVM use Ruby 1.9.2 first before I can do Rails stuff again.
How can I make this permanent?
After you first execute
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
you shouldn't need to do it again. That line appends the necessary file inclusion information RVM into your .bash_profile. If you are using bash (as opposed to zsh, ksh, csh, tcsh or any other shell), then RVM will be accessible each time you open a new session. If you are using a different shell, that line may need to be in a different startup file. For example, if you are using zsh, then you'll probably want to append it to your ~/.zshrc file.
Having done this, simply running rvm --default use ruby-1.9.2 once should ensure that you have the desired version of Ruby by default. Note, you should not need to add this line to your .bash_profile or similar.
try this
rvm --default use ruby-1.9.2
In order to make Terminal (e.g. bash) enable RVM every time you open it, edit ~/.profile and add the following line to it:
[[ -s "/Users/foo/.rvm/scripts/rvm" ]] && source "/Users/foo/.rvm/scripts/rvm" # This loads RVM into a shell session.
Then to make the RVM's version of ruby default, as fl00r has mentioned, run:
rvm --default use ruby-1.9.2
Alternatively, you can add an .rvmrc file to the root folder of your app that uses Rails 3.0.9 and specify which version of Ruby you want to use with that project there:
rvm ruby-1.9.2
Even better, you should create a gemset by running rvm gemset create rails-3.0.9 and update you .rvmrc file to become like this:
rvm ruby-1.9.2#rails-3.0.9
Then run cd into the project once again (you must cd into it once again), and run bundle install.
This way your project will have its own isolated gemset.
this also work for me
rvm --default use 1.9.2

Resources