Is there a way to automatically load rvm on start up?
Every time I open a new terminal window I need to type rvm 1.9.2 to be able to use the gem set. Can I add 1.9.2 as a default?
There are several ways
The normal one is
rvm use 1.9.2 --default
You could also create a file .rvmrc which can also load a specific gemset per folder. For example if you have an application that uses the gemset 1.9.2#myapp, your .rvmrc in myapp could be:
# myapp/.rvmrc
rvm use 1.9.2#myapp --create
you should be able to simply do this;
rvm --default use 1.9.2
Related
How can I use RVM to set a default ruby version for a certain directory? So that every time I cd into that directory, it switches to my preferred version of Ruby.
Directly from the RVM documentation:
RVM supports multiple files allowing to configure a project for automated ruby switching. In any case make sure to add those files to your version control systems as it is part of the project configuration.
Listed in order of precedence:
.rvmrc - shell script allowing full customization of the environment,
.versions.conf - key=value configuration file
.ruby-version - single line ruby-version only
Gemfile" - comment: #ruby=1.9.3 and directive: ruby "1.9.3"
One way is to use a Gemfile and set the ruby version in it. like so:
ruby '2.2.0'
then when you enter the directory you will see the following message from rvm
RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too,
you can ignore these warnings with 'rvm rvmrc warning ignore /Users/danmanstx/rails_projects/app/Gemfile'.
To ignore the warning for all files run 'rvm rvmrc warning ignore allGemfiles'.
Create a .ruby-version file in that directory with your version information. To set version as 2.1.2 for a directory, create the file with only "2.1.2" as the content.
$ cat .ruby-version
2.1.2
in rails 6 you only have to change what's inside of .ruby-version in your app folder
Or simply use rvm --ruby-version ruby_version#gemset --create , --create here will create the gemset if it is not present already. If you don't need to specify a gemset, but instead use the default gemset. leave out #gemset --create. ruby_version for example 2.0.0.
I updated RVM and started switching from .rvmrc to .ruby-gemset and, where necessary, .ruby-version.
However, so far, when I change into a directory with .ruby-gemset, it doesn't automatically start using the correct one as it would with .rvmrc.
Is it supposed to work the same way?
I'm using RVM 1.20.5.
RVM detects .ruby-version and only if it is present it will read .ruby-gemset.
RVM does not reads .ruby-gemset when .ruby-version is not available.
You could try .ruby-version (editted from current):
default
Just getting started with Ruby.
I am trying to use rvm. Now, for Project A I am trying to specify a specify Ruby version and a gemset.
$ cat projecta/.rvmrc
rvm 1.8.7#projecta
My understanding is that the part before # specifies the Ruby version and the the part after # specifies the gemset name. A gemset IMU is to provide a project specific isolated location where you can install gems.
After I check-in this project, what can I do to automate the process of creating the gemset and installing the correct Ruby version for someone else checking the project out at a later date?
Please suggest appropriate alternatives, since I am just getting started with Ruby today.
The Old Way
to make sure gemset / ruby is available use this .rvmrc:
rvm use 1.8.7#projecta --install --create
It will install ruby if missing and create gemset if missing.
And a special note, please do not use 1.8.7, it's deprecated ruby, with almost no support (security patches till half of 2013), you should stick with latest available ruby:
rvm use ruby
which at this time is: 1.9.3-p194
Add On-Demand Syntax
Your syntax won't work as written. If you want to force people to compile rubies and create gemsets on demand, rather than being warned when things don't exist, you want a project .rvmrc file like this:
# Compile rubies on demand.
rvm_install_on_use_flag=1
# Create gemsets on demand.
rvm_gemset_create_on_use_flag=1
# Use ruby-1.8.7 while in project tree.
rvm use 1.8.7
# Use gemset "projecta" while in project tree.
rvm gemset use projecta
There are certainly other ways to do it, but this way makes everything explicit, and you can comment out individual lines if you need to do so.
See Also
https://rvm.io/workflow/rvmrc/
I'm using rvmrc files per project. When I cd into my project the terminal/rvm does not indicate that I'm using a new gemset. How do I set it up?
In case it helps: I'm using oh-my-zsh.
it might depend on your project files, basically rvm will not print information about using when the use keyword is omitted:
rvm 1.9.3 # will be quiet
rvm use 1.9.3 # will print: Using...
the same result will be when you put those in .rvmrc, also generating new .rvmrc with --rvmrc will behave the same way:
rvm 1.9.3 --rvmrc # `cd` will be quiet
rvm use 1.9.3 --rvmrc # `cd` will print: Using...
I want to use per project gemsets. But I don't want to specify the ruby version.
Something like:
#.rvmrc
rvm --create use "#project"
But this give me the following error:
error: Unknown ruby interpreter string component: 'ruby 1.9.2 p136'
info: Now using system ruby.
Is there a way to do what i want?
I'm not sure if that's the case but perhaps
rvm --create use doesn't support params without ruby version.
#.rvmrc
rvm gemset create "project"
rvm gemset use "project"
I didn't check this, just saw at:
http://rvm.beginrescueend.com/gemsets/creating/