rvm not defaulting to newer version of ruby - ruby-on-rails

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

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.

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

How to set default Ruby version with RVM?

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

rvm not found while installing Ruby on Rails

I have been following the tutorial to install Ruby on Rails on the mac from this website:
http://ruby.railstutorial.org/
I installed rvm and it wasn't working. The tutorial said to enter this command:
~ $ [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
After I did that it seemed to have loaded successfully as it said this:
~ DUFF$ rvm reload
RVM reloaded!
~ DUFF$ rvm notes
Notes for Darwin ( Mac OS X )
For Lion, Rubies should be built using gcc rather than llvm-gcc. Since
/usr/bin/gcc is now linked to /usr/bin/llvm-gcc-4.2, add the following to
your shell's start-up file: export CC=gcc-4.2
(The situation with LLVM and Ruby may improve. This is as of 07-23-2011.)
For Snow Leopard be sure to have Xcode Tools Version 3.2.1 (1613) or later
You should download the latest Xcode tools from developer.apple.com.
(This is since the dvd install for Snow Leopard contained bugs).
If you intend on installing MacRuby you must install LLVM first.
If you intend on installing JRuby you must install the JDK.
If you intend on installing IronRuby you must install Mono (version 2.6 or greater is recommended).
To seamlessly abandon the Apple-installed system ruby (ruby 1.8.7 patchlevel 174 for Snow Leopard):
rvm install 1.8.7 # installs patch 302: closest supported version
rvm system ; rvm gemset export system.gems ; rvm 1.8.7 ; rvm gemset import system # migrate your gems
rvm --default 1.8.7
NOTE: For all installations, as of 1.7, RVM no longer autoloads .rvmrc files. In order to return this functionality, you MUST add 'export rvm_project_rvmrc=1' to your $HOME/.rvmrc file. This causes RVM to override 'cd' which, while toggleable even < 1.7, is currently defaulted to 'off'. This knob returns the previous behaviour to active which causes per-project .rvmrc files to be loaded once again.
Example: echo 'export rvm_project_rvmrc=1' >> $HOME/.rvmrc && rvm reload
So after all of that I entered this as directed:
type rvm | head -n1
and it said:
-bash: type: rvm: not found
So after that long introduction my question would be do you know why it is not recognizing the rvm type after it seemed to have installed. I am a complete newbie so please be gentle. I have been having a ton of issues and this seemed to be moving along nicely up until this point.
Any help would be appreciated. Thanks.
Are you following this tutorial? http://beginrescueend.com/rvm/install/
You should run this entire command:
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
That way it's appended to your .bash_profile file, and loaded in every new terminal. The command you entered will only load the rvm function for a single terminal session.
.rvm/scripts/rvm is a shell script itself that loads all necessary functions into your environment.
Have a look at the same question I posted some time ago.
The install guide says to "register" RVM in the terminal this way:
user$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
Basically, when you load the RVM function in your shell, where you're going to put the instruction depends on your distribution; here it's going into .bash_profile.
As a user of Ubuntu, I found using .bashrc instead of .bash_profile worked better.
The difference between .bash_profile and .bashrc is outlined here: http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html

Set Global default Ruby for RVM on machine with multiple (too many?) Rubies

I am struggling to get Rails to deploy on a server that has:
a factory installed Ruby (1.8.7) in /etc/
an updated Ruby (1.9.2p290) in /usr/local/bin/
the Ruby I want to be using(1.9.2p290) in /usr/local/rvm/rubies.
Is there a way to set a GLOBAL default Ruby in RVM for ALL users?
When I set default with rvm --default 1.9.2#railspre it'll work fine for that session. But, when I log back in the ruby switches back to the one in /usr/local/bin. And, due to RVM's hocus pocus, that I don't fully understand, I can't just edit the $PATH for it in .bashrc.
$PATH at login:
/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/git/bin:/opt/subversion/bin:/usr/local/rvm/gems/ruby-1.9.2-p290#railspre/bin:/usr/local/rvm/gems/ruby-1.9.2-p290#global/bin:/usr/local/rvm/rubies/ruby-1.9.2-p290/bin:/usr/local/rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin
$PATH after rvm --default 1.9.2#railspre:
/usr/local/rvm/gems/ruby-1.9.2-p290#railspre/bin:/usr/local/rvm/gems/ruby-1.9.2-p290#global/bin:/usr/local/rvm/rubies/ruby-1.9.2-p290/bin:/usr/local/rvm/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/git/bin:/opt/subversion/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin
No matter what (before or after changing RVM's default) rvm default list says the same thing:
$ rvm default list
rvm rubies
=> ruby-1.9.2-p290 [ ppc ]
Ideas?
Edit- adding requested info
$ type rvm | head -1
rvm is a function
$ which ruby
/usr/local/rvm/rubies/ruby-1.9.2-p290/bin/ruby
$ whereis ruby
/usr/bin/ruby
Please post the result of the following :
type rvm | head -1
rvm notes
which ruby
whereis ruby
rvm list known
Do =>
rvm use 1.9.2 --default
Being root and normal user do =>
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
source .bash_profile
Restart your pc and see if it works.

Resources