Make rvm switch to system ruby on osx - ruby

I have a project that needs to use the system installed version of Ruby on OSX (1.8.7). My default rvm ruby is set to 2.0.0p0 and I want to keep it that way. Using RVM 1.19.6 (latest?)
From everything that I've read I should be able to simply create a .ruby-version file in my project directory and when I switch to that directory it should automatically switch to the system ruby.
According to the documentation I should be able to simply issue
rvm --create --ruby-version use system#myproject
and that should take care of everything. This however gives me
Unrecognized command line argument: 'rmvrc' ( see: 'rvm usage' )
What am I doing wrong? Is the documentation out of date?

Try creating a .rvmrc file in your project root, like:
echo 'rvm system#myproject --create' > .rvmrc
rvm reload
However I wouldn't recommend using system version, rvm installs the different ruby versions in its own directory and manages them easily. Alas system version is a bit outdated.

Related

version of Ruby for cucumber

I have no knowledge in Ruby, but I need to run some tests in it. The code is in Ruby and Cucumber. I use intellij on Mac. When I first open intellij cucumber step definition where not recognised from feature file. In terminal I got:
Required ruby-2.1.2 is not installed.
To install do: 'rvm install "ruby-2.1.2"'
but
$ which ruby
/Users/myuser/.rvm/rubies/ruby-2.4.1/bin/ruby
so I run the install command as suggested and now I get
$ which ruby
/Users/myuser/.rvm/rubies/ruby-2.1.2/bin/ruby
Now my feature files connected to step definition as well. I will appreciate if anyone could explain me what happened. What prompted me to downgrade the version of Ruby and how it fixed cucumber.
Make sure you have ruby 2.1.2 set in File -> Settings -> Languages & Frameworks -> Ruby SDK and Gems
What I suspect is happening is you have run rvm use 2.1.2 in the terminal but when your IDE runs something it is using the ruby version set in the settings.
You probably have a .ruby_version file in the project root directory. This will enforce a specific version of Ruby. So the person who put it there is who to ask why the version was restricted like that. There may have been a good reason, such as that's what is being used by all your users.
It has nothing to do with Cucumber. rvm has some kind of operating system hook, I think, that runs whenever you cd into a directory. It looks for its special control fiels such as .ruby_version and .rvmrc file. This page describes this in more detail: https://rvm.io/workflow/projects.

RVM set per user ruby versions

How would you setup RVM, so that some users automatically get one version of ruby, while others get a different version of ruby?
For example, I want the following users to always have these version of ruby
git => 1.9
root => system
bob => 2.0
Looking at the rvm documenation, I can't find any referernce to per user settings.
How could I accomplish this?
I'm hoping there is a config file that can be placed somewhere. Because I'm automating the server installation with puppet, running rvm commands by hand isn't feasable.
Update
I've installed rvm, using this puppet module, https://forge.puppetlabs.com/maestrodev/rvm
It appears that all users have access to the rvm command.
You would just need to make a .rvmrc file for each user's $HOME directory.
http://rvm.io/workflow/rvmrc
The maestrodev/rvm module installs rvm and rubies system wide, then you need to use rvm:system_user to add each user to the rvm group
rvm::system_user { bturner: ; jdoe: ; jsmith: ; }
and as msergeant mentioned, add the .rvmrc to each user' home.

RVM and automatically switching gemsets

Is it possible to have rvm know which gemset it should be using while navigating under a certain directory, much in the same way you can have git the current branch's information just by navigating under that directory?
I understand how git works that way since each directory has its own .git directory in the root, but didn't know if it was possible since .rvm is more of a user-wide configuration. Or perhaps the answer is to make a .rvm file within each directory?
For others visiting this, there is a new way to do this, without having to allow arbitrary shell script to be executed in a .rvmrc file.
Create a file named .ruby-gemset containing only the gemset name in.
gemset
Need an up to date version of rvm for this to work.
You can also specify the ruby version by creating a file named .ruby-version containing only the ruby version:
1.9.3
This format also has the advantage of being compatible with rbenv and rbfu.
If you have existing projects using the deprecated .rvmrc, you can convert them to the new format using the command:
rvm rvmrc to .ruby-version
Create a .rvmrc file in each project/branch with contents similar to this:
rvm gemset use xxxx
Save it. Next time you cd into that folder, you'll probably get a security prompt from RVM to make sure you want to use that .rvmrc. After accepting, you'll see "Now using gemset 'xxxx'" every time you navigate into that folder.
I find the easiest way to achieve this is to navigate to the project folder and then use the following command:
rvm --rvmrc --create <ruby>#<desired-gemset-name>
e.g. rvm --rvmrc --create 1.9.2-p290#testing_gemset
In one stroke, RVM will create the .rvmrc file, populate it, install the correct ruby version - if necessary - and (usually) switch to the correct ruby version and gemset. I say usually because I find that I sometimes have to cd . after performing that command to get RVM to pick up the changes.
Create a .ruby-version file with the contents [ruby version]#[gemset] in the project folder.
Example:
$ rvm gemset list
gemsets for ruby-2.6.3 (found in /home/ec2-user/.rvm/gems/ruby-2.6.3)
(default)
hello
=> sample
toy
$ echo "2.6.3#sample" > .ruby-version
If you cannot get .ruby-version / .ruby-gemset working, consider whether your terminal is using shell login and try running the command in the shell section at http://rvm.io/support/faq:
$ rvm get [head|stable] --auto
It is possible: http://rvm.io/workflow/rvmrc/:
rvm use ruby#gemset

How to tell Terminal which version of Ruby to use?

I have two related questions that I was hoping someone could help out with.
I recently installed Ruby 1.9.2 on my Mac (running Snow Leopard 10.6.4) and I haven’t been able to figure out how to get Terminal to use the new Ruby as a default, rather than the factory-installed Ruby 1.8.7. The old Ruby 1.8.7 is located in my ~/usr/bin/ruby directory while the new Ruby 1.9.2 is in ~/usr/local/bin/ruby. Someone said that I need to put the new version of Ruby's directory in the PATH prior to the old version's directory so that the system looks there first - is this correct? If so, can anyone provide step by step instructions on how to do this?
I’ve created a new directory but can’t seem to figure out the correct way to add that directory to my PATH using the Terminal bash shell. I tried using the instructions that I found here (http://www.macgasm.net/2008/04/10/ad...thin-terminal/) twice but they didn't work for me. The directory containing my program ("Ruby_Programs") shows up in the PATH but when I try to run "ruby newprogram.rb" from the command line it results in ":ruby: No such file or directory -- newprogram.rb (LoadError)". The file definitely exists and is a functional Ruby program. I did change the name of the directory to "Ruby Programs" and then back to "Ruby_Programs" - could that have somehow caused this problem?
Any help would be greatly appreciated. Here is my current PATH:
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/sbrriffe/src:/usr/X11/bin:/Users/sbriffe/Ruby_Programs/:
You might want to check out rvm. You can install multiple versions of ruby side by side and easily switch between them. If you follow the rvm installation notes you won't have any more path problems.
Your Ruby Programs directory shouldn't be in your path: the location of your ruby interpreter should be. Then, you cd to the location of your ruby program, and run it from there: ruby program.rb.
Since you are on a Mac, check out homebrew for something that will make installing software easier. I have my homebrew set up in /usr/local, and it works great.
Once you have installed stuff where you need it, then you'll want to adjust your $PATH. The items in $PATH are searched in the order they appear, so in your ~/.bashrc, you'll want to add:
export PATH=/usr/local/bin:$PATH
To make sure /usr/local/bin gets searched before /usr/bin.
I would use RVM to get everything installed, and then once you have RVM installed it is easy to set your default Ruby version.
Check out https://rvm.io/ -- once you have that installed you can change your default by using : $ rvm use 1.9.2 --default
hope that helps- you can do this with any version, not only 1.9.2

Getting Textmate to recognize Ruby version upgrade

I used the instructions at http://bparanj.blogspot.com/2010/06/installing-ruby-191-on-snow-leopard.html to install Ruby version 1.92 on my Mac running Snow Leopard. The only deviation is in step 3, which calls for .bash_profile to be updated. I have .profile, but not .bash_profile, in my home directory, so I added the export command to the last line of .profile. The installation completed successfully (with the same two warning messages as mentioned, which I too disregarded), as Ruby -v in a terminal prints
ruby 1.9.2dev (2010-07-02 revision 28524) [x86_64-darwin10.4.0].
When I run Textmate, however, cntrl-R invokes Ruby version 1.8.7, as it did before the 1.9.2 installation. In Textmate's Preferences-Advanced-Shell Variables, TM_RUBY is set to /usr/bin/ruby. The (binary alias) file 'ruby' has not been updated. What is the easiest way for me to instruct Textmate to use the newer version of Ruby? Please note my understanding of OS X is relatively limited.
What is the easiest way for me to
instruct Ruby to use the newer version
of Ruby?
I believe you mean "What is the easiest way for me to instruct Textmate to use the newer version of Ruby?"
Assuming that is the case, have you tried to edit the TM_RUBY shell variable to point to your newly installed version? According to the docs you referenced, it should be somewhere under /usr/local (most likely /usr/local/bin/ruby).
You can find out the location of your ruby installation by typing the following in your terminal window:
$ which ruby
/usr/local/bin/ruby
then perform the following to verify the version
$ ruby -v
Once you have the proper ruby path, in Textmate, double-click the 'value' of the TM_RUBY shell variable & type in the path to your 1.9.2 install.
Why not just create a .bash_profile file in your home directory?

Resources