How do I associate a new rvm install with existing ruby versions? - ruby

I was having a problem with RVM, so I uninstalled and re-installed it.
The truth is I actually tried rbenv, but that didn't work out for me so I am trying to get rvm up and running again - without having to install duplicate versions of Ruby.
I have at least 1 existing version of Ruby installed:
ruby --version
ruby 1.8.7 (2011-12-28 patchlevel 357) [universal-darwin11.0]
But when I do rvm list I get a blank list:
bash-3.2$ rvm list
rvm rubies
# Default ruby not set. Try 'rvm alias create default <ruby>'.
# => - current
# =* - current && default
# * - default
So my question has two parts:
How do I see all the versions of Ruby on my system (given that rvm is not showing me any)?
How do I associate the new RVM install with the existing versions of Ruby?
Or am I better off removing all existing versions of Ruby and re-installing everything? That seems like a pain in the ass though.

You can add an existing ruby to rvm using:
rvm mount /path/to/ruby
or:
rvm automount
but be careful as ruby installed in system might have hardcoded paths for gems - so gemsets would not work with it.
There is also new way of adding binary rubies (already compiled), for list of available builds for your platform run:
rvm list remote
and you can install those rubies using:
rvm mount -r 1.9.3
This might be default way of installing ruby to avoid compilation in next stable release of RVM - but it will work only for ruby 1.9.3+.

You don't want to associate RVM with an existing Ruby, you just want to install a new Ruby.
You don't want to remove the system Ruby, either; OS X depends on it.
Install a new 1.8.7 under rvm, this way you can associate your own gemsets with it. Let OS X manage the default system Ruby, you just ignore it and use your own, managed solely by rvm.
(If you decide to go the rvm route.)

Related

How to set specific Ruby version for projects(no rvm and rbenv)

I worked on some project when in some moment I have to change Ruby version for some other project. Now when I want to go back to first project, I'm getting some errors because of Ruby version. The question is how to change Ruby version(currently I'm on RVM-installed Ruby 2.5.1) and want to back to Ruby 2.4.5 but it wasn't installed via Rvm or Rbenv, just clean installation.
I know how to change Ruby version via Rvm, but how to change to version which is not installed with any addition (Rvm or Rbenv)
Even though this doesn't answer your question directly, I would recommend against using both RVM Ruby and system Ruby together. RVM was not designed to work that way and every issue arising from this kind of installation would be quite difficult to debug, particularly if you are a beginner.
So the easiest way to go would be to remove the system Ruby completely and create a 2nd RVM gemset for your other project. (This is how RVM is intended to be used, actually.)
See doc: https://rvm.io/gemsets/creating
https://rvm.io/gemsets/basics
If you have more then one projects with different ruby versions then we need to use rvm gemsets to avoid conflicts.
Steps to be followed:
rvm gemset create sriharsh
rvm use 2.2.1#sriharsh --create
rvm gemset list (to check list of gemsets)
rvm list (list of rvm rubbies)
However, if you are using Bundler then you don't need to use RVM Gemsets. Prepending any command with bundle exec will execute it in the context of the project's Gemfile.
For ex:
bundle exec rails s

ruby 1.8.7 & ruby 2 without rmv, failed instalation

I installed ruby 2.0 (from sources) in a centos that already had ruby 1.8.7.
I did not know that there was a previous installation.
I also noticed that had installed RVM. Now it doesn't work.
The RVM output
$ /usr/local/rvm/bin/rvm list
$ rvm rubies
No rvm rubies installed yet. Try 'rvm help install'.
From what I understand, RVM does not know there is already a installed version of Ruby.
Is possible uninstall all versions and reinstall ruby with RVM?
RVM allows "mounting" system rubies:
rvm mount /path/to/ruby
Or assuming all rubies are added to PATH
rvm automount
RVM will find any ruby binary available on PATH and will add it to rvm list
RVM does not care for rubies installed at the system level. It installs rubies to RVMs own folder inside of the users home directory. You should just install the desired ruby version using RVM. Since the RVM rubies should have precedence over the system-installed ruby, that should work out just fine.

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.

What is the point of installing the same version of Ruby through RVM as the system Ruby?

I've been using the default system ruby version 1.8.7 without RVM for a few rails projects and have not run into any problems. I just recently installed RVM, and after running rvm requirements I get this output:
To use an RVM installed Ruby as default, instead of the system ruby:
rvm install 1.8.7 # installs patch 357: closest supported version
rvm system ; rvm gemset export system.gems ; rvm 1.8.7 ; rvm gemset import system.gems # migrate your gems
rvm alias create default 1.8.7
I believe what these commands do are to install the same gems that have already been installed using the system ruby under the RVM installed ruby.
My questions are, am I right in what these commands do? and if I am right, why is it important to do this, because if I wanted to use an RVM installed Ruby of a different version like 1.9.2, wouldn't it already separate gems in that version from the system's ruby?
The one thing that springs to mind is, if you use the system Ruby, you'll use it slightly differently that RVM's Rubies--for example, you'll likely need to use sudo to install gems. Furthermore, you won't be able to use many of RVM's features, like gemsets, with the system Ruby.
Well one reason I can think of is that you don't wanna worry about your system not working even if the system ruby gets updated.
My questions are, am I right in what these commands do?
You are right in what they do. The first command installs Ruby 1.8.7, the second command installs all the gems currently install on your system Ruby installation in the new RVM Ruby 1.8.7 installation, and the third command sets your default version of Ruby to be the RVM Ruby 1.8.7.
and if I am right, why is it important to do this, because if I wanted to use an RVM installed Ruby of a different version like 1.9.2, wouldn't it already separate gems in that version from the system's ruby?
The second command is actually more of about convenience than necessity. Yes, the gems install in the RVM 1.8.7 will be completely separate from the ones installed in the system version of Ruby; however, if you didn't run the second command, you're RVM 1.8.7 would start out with almost no gems (only the defaults). That means that you would need to go through and manually install the gems that you need to get your project up and running. Instead of doing that, the second command allows you to just install the same gems you've already installed in the system version of Ruby to the RVM 1.8.7 version—it doesn't migrate them, it just makes a copy of them. After the second command, there are two distinct sets of the exact same gems: one in the system Ruby and one in the RVM 1.8.7 Ruby. So, if you were to update gems in either of the Rubies, they would get updated, but the other version's gems would be unaffected.
Hope this helps answer your question.

Make RVM ignore ruby patch level

Currently, my rvm based projects specify rvm 1.8.7#gemset in .rvmrc. This means that when I am installing the gemset of a new project, it will default to the latest patch level of 1.8.7, eg. ruby-1.8.7-p352 . Now I don't want to hard code '1.8.7-p352' in the rvmrc as other developers(or other projects) might have some other patch levels installed on their machine(from other projects) and also I don't want to install different patch levels of ruby on my machine.
Is there a way to make rvm ignore the patch level and just make it use any version of 1.8.7 installed - so that I can use one patchlevel of Ruby 1.8.7 across all projects.
The thing you want to set up is called an rvm alias. See: http://rvm.io/rubies/alias
For your example the commands would be:
rvm alias create 1.8.7 ruby-1.8.7-p352

Resources