Make RVM ignore ruby patch level - ruby

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

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

How do I make Octopress use the system version of Ruby?

I am trying to setup Octopress on my Mac. The default version of Ruby on my Mac was 1.8.7 but I have upgraded it to 2.0.0.
If I do:
which ruby
it prints:
/Users/liqiushi/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
After cloning my existed sources from github and 'cd'ing into that folder, I got the following error:
You are using '.rvmrc', it requires trusting, it is slower and it is
not compatible with other ruby managers, you can switch to
'.ruby-version' using 'rvm rvmrc to [.]ruby-version' or ignore this
warning with 'rvm rvmrc warning ignore
/Users/liqiushi/Documents/photosynthesiis.github.com/.rvmrc', '.rvmrc'
will continue to be the default project file in RVM 1 and RVM 2, to
ignore the warning for all files run 'rvm rvmrc warning ignore
all.rvmrcs
ruby-1.9.3-p448 is not installed.
To install do: 'rvm install ruby-1.9.3-p448'
If I do:
ruby -v
in the Octopress folder it prints:
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
And, if I do:
which ruby
It prints:
/usr/bin/ruby
Can anyone tell how to make Octopress use the Ruby I just upgraded in my Mac instead of using 1.8.7?
Octopress is using your system ruby, ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0].
You're using RVM, the ruby-2.0.0-p247 is a ruby you've installed. The repository has an .rvmrc file saying it wants ruby-1.9.3-p448. Try installing it, or change what the .rvmrc wants.
edit: The error message tells you what to do:
ruby-1.9.3-p448 is not installed.
To install do: 'rvm install ruby-1.9.3-p448'
RVM has a "default" Ruby that, immediately after installation, you should have set using:
rvm use 2.0.0 --default
See RVM's rvm help use command and "Setting the default Ruby" for more information. That covers the cases where you don't have a .rvmrc file in the directory.
For directories where it exists, you can remove the file:
rm ./.rvmrc
Or edit it to contain the information for the version you do want RVM to use when you cd into the directory. See RVM's "RVM Best Practices" for good tips on dealing with RVM in general and the tip of the discussion about using .rvmrc files. RVM's "rvmrc" capability is pretty nice. The previous link 'splains it nicely and details settings you can adjust to make your life a lot easier.
In that page you'd find:
As of RVM 1.8.0, after a survey where greater than 80% of respondants wanted the feature on by default, automatic loading of project .rvmrc files is opt-out by default (therefore on). In order to disable this feature, set the following value in either /etc/rvmrc or ~/.rvmrc:
rvm_project_rvmrc=0

Can chruby and chgems replace rvm's gemset?

I am currently using rvm on my development machine for switch between rubies (mainly 1.9.x and 1.8.7). Then I came across chruby and found the "Does not hook cd" feature attractive.
Can chruby + chgems replace rmv's gemset feature?
Before:
$ rvm 1.8.7
will switch to ruby 1.8.7 with the 1.8.7 set of gems for my older rails projects. And:
$ rvm 1.9.3
will switch to ruby 1.9.3 with the 1.9.3 set of gems for my new rails projects.
How can that be achived by chruby and chgems?
I'll take a run at this question since I use Chruby and Chgems. I am on Mac OS X, and I have chruby installed via Homebrew.
In my .bashrc file:
source /usr/local/share/chruby/chruby.sh
chruby ruby-2.0.0-p195
The source line is part of configuration for Chruby.
The second line sets a default version of Ruby for my system (in my case Ruby 2.0.0). Note: As of Chruby 0.3.6 this belongs in .bashrc instead of .bash_profile.
In my .bash_profile:
source /usr/local/share/chruby/auto.sh
This line sets Auto-switching feature in Chruby.
I still have some projects using Ruby 1.9.3 so for those apps I have a .ruby-version file in the root of the app. with one line ruby-1.9.3
When you cd into the directory for your app, type chgems and then you can bundle install and what not. You can confirm things are working by entering gem env
To make my life easier I added .bash_aliases for example:
alias myapp='cd ~/Sites/myapp && chgems'
I have been using these together for several months now and really like the combination and yes from what I can tell Chgems does a great job replicating the gemset feature of RVM. I highly recommend you read the docs for both Chruby and Chgems projects as this is all covered. In your case, you may not want to set a default Ruby and just use .ruby-version to set it for each app.

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

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.)

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.

Resources