rvm doesn't notify when using a new gemset - ruby

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

Related

Using RVM via bash script

I wanted to write a small bash script to automatically setup the correct ruby version and gemset for a new project. For testing I have rvm installed with ruby 2.3.1 and two gemsets: foo and bar.
Even a simple test like this doesn't return what expected:
$ rvm current
ruby-2.3.1#foo
$ ./script
Using ruby-2.3.1 with gemset bar
Using /(...)/.rvm/gems/ruby-2.3.1 with gemset bar
ruby-2.3.1#bar
$ rvm current
ruby-2.3.1#foo
Contents of the script:
#!/bin/bash --login
rvm gemset use bar
rvm use 2.3.1#bar
rvm current
Other operations like installing rubies or creating gemsets seem to work, I just can't get use to modify the current version used by the script caller. Any ideas?
The answer was obviously simple, I should have called the script using
. ./script

rvm gemset with a specific ruby patch e.g. pNNN

I want to create a gemset with a specific patch version of ruby. Generally I use
rvm use 2.0.0#billslim --create
without issue, however i need to use 2.0.0p481, but specifying p481 doesn't work e.g.
rvm use 2.0.0-481#billslim --create
and if i only use 2.0.0 it always try to install p594.
I've tried
rvm use 2.0.0-481#billslim --create
rvm use 2.0.0p481#billslim --create
rvm use 2.0.0#billslim -l 481 --create
rvm --ruby-version use 2.0.0p481 # unknown ruby string, BUT
rvm --ruby-version use ruby-2.0.0p481 # also gives unknown ruby string
adding a .ruby-version file in my repository root e.g. echo 'ruby-2.0.0p481' > .ruby-version
different formats of the strings e.g. ruby-2.0.0 and ruby-2.0.0-p481 but these result in 'unknown ruby string'
nothing works...
the rvm.io docs don't seem to mention patch versions much when doing gem sets
the other info suggests patch versions should work the suggested formats don't work.
of course the only combination i didn't try, works!
rvm use ruby-2.0.0-p481#billslim --create
doh!

Set a default Ruby version for a specific directory (RVM)

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.

How to automatically start Ruby Version Manager

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

RVM: Create a gemset for whatever ruby is currently running

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/

Resources