DIfferent versions of ruby in ubuntu - ruby

I recently started following M Hartls tutorials on how to build a simple app using RoR.
I nearly wasted one full day on installing RVM and the ruby, since the default RVM on ubuntu is buggy. Once I install ruby through RVM
curl -L https://get.rvm.io | bash -s stable --ruby
it says it installed ruby 2.x version.
but when I type
ruby -v
It says the ruby version is 1.8.x. Why is that?

Your default ruby version is set to 1.8.x.
Type "rvm list" to list installed ruby versions "*" will appear next to your default.
Type "rvm use x.x.x" to use a different version of ruby.
To set a different default version of ruby type "rvm --default use x.x.x".

I think you missed the message given after installing RVM. It's something like:
Please make sure the following line is somewhere in your .bashrc:
source /home/<username>/.rvm/scripts/rvm
What is the output of ruby -v after you executed that line in the console?

If you are using RVM then:
do
rvm list
this will show list of installed rubies
and the do
rvm use XXXXXXX
XXXXX means the version you want to use from the list.
This will use the specified ruby. but after opening new terminal it might be again changed automatically. To avoid this use :
rvm use XXXXXX --default
For example of mine system:
rvm list
rvm rubies
ruby-1.9.3-p545 [ x86_64 ]
=* ruby-2.0.0-p451 [ x86_64 ]
# => - current
# =* - current && default
# * - default
$ rvm use 2.0.0
Using .rvm/gems/ruby-2.0.0-p451
$ rvm use 2.0.0 --default
Using .rvm/gems/ruby-2.0.0-p451

Related

Installing Ruby 2.2.3 on Ubuntu

This problem probably has an obvious answer to anyone who has used Ruby on linux for a long time, but I can't really get a good answer via Google.
I'm trying to check out the Rails 5 beta, which requires Ruby 2.2.2 or greater. I've installed the RVM (Ruby Version Manager) and set my ruby version to 2.2.3. Running rvm list in the terminal results in the following output:
rvm rubies
=* ruby-2.2.3 [ x86_64 ]
# => - current
# =* - current && default
# * - default
Okay, great. I have Ruby 2.2.3 installed. Let's try bundle update:
Installing rack 2.0.0.alpha (was 1.6.4)
Gem::InstallError: rack requires Ruby version >= 2.2.2.
Okay, that's weird. What version of ruby do I have? Running ruby -v gives me this:
ruby 2.1.5p273 (2014-11-13) [x86_64-linux-gnu]
So... do I have 2.2.3 or not? What gives?
Since you are using bundle, I would suggest you to check your Gemfile for ruby version. You can also test it with bundle exec ruby -v
Also try:
rvm use ruby-2.2.3
bundle exec ruby -v
Maybe by setting the default Ruby version on rvm to the one you have (ruby-2.2.3) solves the problem, by doing rvm --default use ruby-2.2.3. Then reload the bash and execute ruby -v to check if the default version of Ruby was changed properly and then try again to execute the bundle install command.
If you don't know zsh and oh-my-zsh, I highly recommend for this kind of things. You could configure the terminal in order to show you the current version of Ruby and Rails that you're using every moment. Check it here: http://ohmyz.sh/
In addition to doing rvm use --default 2.2.3 or rvm use 2.2.3 make sure that you don't have the ruby package from apt (or whatever package manager) still installed. For some reason, that ruby package could take precedence over an RVM Ruby.
Also, try doing rvm uninstall 2.1.5 to force your system to default to 2.2.3... You can always reinstall 2.1.5 later and, if this issue persists, 2.2.3 should stick as your default.

RVM setting default ruby is temporary

So I've been trying to set my default Ruby version to 2.1.2, but I also have 2.0.0 installed and use it occasionally. When I run the command rvm use --default 2.1.2, it works, displaying Using /home/ben/.rvm/gems/ruby-2.1.2 like it should. If I run ruby -v, it returns 2.1.2. Everything's fine there.
However, if I open a new terminal window, and I run ruby -v, it displays 2.0.0. If I do rvm list, it displays the following:
➜ ~ rvm list
rvm rubies
=> ruby-2.0.0-p481 [ x86_64 ]
* ruby-2.1.2 [ x86_64 ]
# => - current
# =* - current && default
# * - default
It basically says that version 2.1.2 is the default, but it is currently using 2.0.0. I don't understand why this would happen, if it is the default, it should start up using that one.
rvm --default use 2.1.2
.......................................
Close, but not quite. From rvm help use:
To set a ruby as the user default, use the --default option.
$ rvm use 1.9.3 --default
edit: as 7stud posted, it works with --default before as well, just not in the middle.

Can't find Ruby 1.9.2 after installing RVM

I'm on Linux Ubuntu 12.04, and I first installed Ruby 1.9.2.
After I tried installing rvm to use Octopress, ruby --version in bash results in ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
How can I use RVM with ruby 1.9.2?
I don't really understand what RVM is all about...
The 1.9.2 version you installed first is not accessible from rvm.
While working with rvm, only the list of rubies installed through rvm is served. The previously installed versions of ruby - while still present in the filesystem - are not included.
With the steps you have done so far, you have a 1.9.2 version installed in one location, and a 1.8.7 version installed as part of rvm.
Install 1.9,2 version by running the rvm install 1.9.2 command. After that, when you run the rvm list command, you should see an output similar to the following:
$ rvm list
rvm rubies
ruby-1.8.7-p358 [ i686 ]
=* ruby-1.9.2-p320 [ x86_64 ]
# => - current
# =* - current && default
# * - default
You can switch between different versions of ruby managed by rvm with the rvm use 1.8.7 / rvm use 1.9.2 commands.
Here's a short blogpost with a good intro to rvm: Get started right with RVM
RVM is a version manager which enables you to decide which of multiple installed Ruby versions you want to use in your current shell session. RVM does this by providing a shell function named rvm which can be used to switch between versions in the current session. This changes environment variables, especially the GEM_HOME and PATH, to match the currently selected Ruby installation.
Every installed Ruby version can be selected by a specific identifier string. If you had a system-wide Ruby installation already before you installed RVM, that one should be referenced by the string system. The newly installed version in your case should be called 1.9.2.
To make RVM work as intended, it is necessary to load the rvm shell function into your shell. How to do this is described in the RVM Installation Documentation in section 2 - "Load RVM into your shell sessions as a function".
You can see if the shell function is correctly loaded when the command type rvm | head -n1 responds with:
rvm is a shell function
If not correctly loaded it will tell you something like this:
rvm is /home/someone/.rvm/bin/rvm
If you finally have it working you can switch your active Ruby version with commands like rvm 1.9.2 or rvm system. You can get a list of all Ruby versions and their identifier strings recognized by RVM by the command rvm list.
You can also specify which Ruby version shall be enabled in all new shell sessions from the beginning by issuing the following command once:
rvm --default 1.9.2
Perhaps you have not yet switched to the ruby version with:
rvm use 1.9.2 (assuming you did rvm install 1.9.2)
for a more general explanation I gave an answer here which might help.

Ruby 1.8.7 upgrade to ruby 1.9.2

I am going through this tutorial, but I already had Ruby 1.8.7 installed. I need to have 1.9.2/1.9.3 version.
I started to use RVM.
$ rvm list rubies
rvm rubies
ruby-1.8.7-p358 [ x86_64 ]
ruby-1.9.2-p318 [ x86_64 ]
=* ruby-1.9.2-p320 [ x86_64 ]
ruby-1.9.3-p194 [ x86_64 ]
# => - current
# =* - current && default
# * - default
but if I run ruby -v it returns still 1.8.7.
$ ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
other return values:
$ whereis ruby
ruby: /usr/bin/ruby /usr/bin/ruby1.8 /usr/lib/ruby /usr/share/man/man1/ruby.1.gz
$ which rails
/usr/local/bin/rails
$ which ruby
/usr/bin/ruby
When you're typing ruby you're still hitting the system ruby, not the rvm ruby.
Did you follow all the directions here: https://rvm.io//rvm/install/ ?
It looks like you're running Linux -- did you see this section in the rvm install docs?
If you open a new shell and running:
$ type rvm | head -1
does not show "rvm is a function", RVM isn't being sourced correctly.
Ensure that RVM is sourced after any path settings as RVM and manipulates the path. If you don't do this, RVM may not work as expected.
If you are using GNOME on Red Hat, CentOS or Fedora, ensure that the Run command as login shell option is checked under the Title and Command tab in Profile Preferences. After changing this setting, you may need to exit your console session and start a new one before the changes take affect.
Also, rvm adds some lines to your .bashrc file to load itself into memory whenever you open a console session. It looks like this may be your issue.
In my .bashrc, for example, rvm inserted the following:
export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/lib/postgresql84/bin:$PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
Is there something similar in yours? Also, if you're using z-shell you may need to take some extra steps that are outlined in the install docs.
Try
$ rvm use ruby-1.9.2-p320
then
$ ruby -v
what does this return?
This should change your ruby version to ruby-1.9.2-p320 in the current console and if you want it on every new opened terminal you may use --default option
try
$ rvm --default use ruby-1.9.2-p320
then
$ruby -v
should return ruby-1.9.2-p320 version in the current and in every new window terminal opened.
Any time you want to return to your system ruby installation
use
$ rvm use system

How do I update Ruby-interpreters with RVM?

I installed RVM with a few versions of Ruby-interpreters some time ago.
How I can to update it, because new versions are already released?
I found only one way: rvm install 1.9.2-rc1 && rvm remove 1.9.2-preview1, but my gems are lost.
Can I update branches time to time? I haven't found any tips in the documentation.
Use the rvm upgrade 1.9.2-preview1 1.9.2-rc1 command or watch this screencast
[Edit: rvm has a new command to upgrade-- you likely want to use the answer by andy318]
AFAIK, there is no automatic way to do this at the moment, but something like this enables you to keep your gems:
rvm use 1.9.2-preview1
rvm gemset export
rvm install 1.9.2-rc1
rvm use 1.9.2-rc1
rvm gemset import
rvm remove 1.9.2-preview1
Now, for automating updates, you would have to detect version changes, that is easy, as you can simply use the return value of rvm use 1.9.2. Finding out what the new version is (1.9.2-rc1) is unnecessary, as it is aliased as 1.9.2. The trick is to find the latest installed version of 1.9.2. You could do something like this in a cron job:
# make sure you source rvm first
rvm update --head
rvm reload
if [ ! rvm use 1.9.2 ]; then
for ruby_version in `rvm list strings`; do
# find the latest version of 1.9.2
case $ruby_version in
ruby-1.9.2-*) latest192=$ruby_version;;
esac
done
rvm use $latest192
rvm gemset export 192.gems
rvm install 1.9.2
rvm use 1.9.2
rvm gemset import 192
rvm remove $latest192
fi
Did not try that, but I have similar code in my update script. I also slipped in a gem update and other stuff.
Feel free to visit the #rvm IRC channel on Freenode.
Current rvm version provides an easier way to do this. The 'upgrade' option will migrate gem sets, wrappers and environment files -
$ rvm upgrade 1.9.2-p136 1.9.2-p180
To find out if there is a more recent stable version of a ruby implementation for you to upgrade to, first get the latest version of RVM and then enumerate the known versions of Ruby.
$ rvm get stable
$ rvm list known
You can compare this the ruby versions installed on your system
$ rvm list rubies
you can install latest rvm and ruby by :
$ \curl -L https://get.rvm.io | bash -s stable --ruby
and check all the ruby version with stability
$ rvm list known
can also check details here : http://www.ruby-lang.org/en/downloads/
$ rvm install ruby 2.0.0-p247
Use when you want to download specific version or know this is stable.
There's a fantastic RVM GUI called JewelryBox that I use to manage my Ruby versions
http://jewelrybox.unfiniti.com
I think that is:
rvm all do gemset update

Resources