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.
Related
Of all the days I chose today to switch from rvm to rbenv. All went well far enough, there are good tutorials on this, but the fun stopped when I tried to install ruby 1.9.3.
rbenv install 1.9.3
proposed to install 1.9.3-p448 as the current version which seems ok to me, so I tried
rbenv install 1.9.3-p448
and went down from there on. It will look up something on ...cloudfront.net and then tried to fetch ruby-1.9.3-p448.tar.gz from the "usual location" which it considers to be
http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p448.tar.gz
which fails with
/usr/local/bin/ruby-build: line 144: pushd: ruby-1.9.3-p448: No such file or directory
plus a final 404-error and a host of followup error messages.
As it turns out the link above is identical to the one published on http://www.ruby-lang.org/en/downloads/ which I would consider as "official" a link as you might find for Ruby. So if you go to ruby-lang.org manually (or using the link above) you will also find a broken download (as of 2013-08-06 17:06)!
I guess this is a temporary issue and the downloads will return (2.0.0 link is also broken by the way). Not to much of a problem for me at the moment as 1.9.2 can still be installed (and I am stuck with that at my current hosting provider ...), but anyways: Are there any other options I would have to install a ruby with rbenv without these "official" distributions?
Looks like ruby-lang.org has been going on and off line for a couple of hours now.
ruby-lang status: http://www.ruby-lang.org/en/news/2013/08/06/status-issue/
GitHub Issue: https://github.com/ruby/www.ruby-lang.org/issues/259
just tested overriding the mirror for ruby-build in cap...
rbenv uses ruby-build. You can override the mirror in ruby-build url in 2 ways:
Specifying a custom ruby version (requires you to write out a config in ruby-build/share/ruby-build/my-custom-ruby
Overriding the mirror url (requires the checksum to be the same), i.e., RUBY_BUILD_MIRROR_URL= http://mirrors.ibiblio.org/ruby/2.0/ruby-2.0.0-p247.tar.gz
env RUBY_BUILD_MIRROR_URL=http://mirrors.ibiblio.org/ruby/2.0/ruby-2.0.0-p247.tar.gz ~/.rbenv/bin/rbenv install 2.0.0-p247
I had this same problem, and I was able to work around it by editing the ruby-build recipe for the particular version of Ruby I needed to download.
I installed ruby-build as an rbenv plugin, so the recipe lives here:
~/.rbenv/plugins/ruby-build/share/ruby-build
Here's the edited version of the recipe:
install_package "yaml-0.1.4" "http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz#36c852831d02cf90508c29852361d01b"
install_package "ruby-1.9.3-p448" "http://mirrors.ibiblio.org/ruby/1.9/ruby-1.9.3-p448.tar.gz#a893cff26bcf351b8975ebf2a63b1023"
#install_package "ruby-1.9.3-p448" "ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p448.tar.gz#a893cff26bcf351b8975ebf2a63b1023"
I did not try this, but you might be able to achieve a similar result by following the instructions for specifying package download mirrors.
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.
I've just updated RVM, and in place of the old .rvmrc, it auto-created .ruby-gemset and .ruby-version.
I've always had .rvmrc files with contents like rvm use --create default#project_name. However, .ruby-version contains the specific Ruby version I'm running rather than default. I'm hesitant to check this in.
Also, I heard someone say on a podcast that one shouldn't check in .ruby-gemset because others may have their own preferences about how to name gemsets.
When should or shouldn't I check in .ruby-gemset and/or .ruby-version?
Specifically:
What are some of the tradeoffs?
How does the type of project affect the decision (for example, applications vs gems)?
If they should be checked in, how does the type of project affect what should go in these files?
Citations from from the creators of tools like rvm, rbenv, etc would be appreciated in an answer.
For standard projects
Check in .ruby-version if your project depends on a ruby like ruby-2.0.0.
Check in .ruby-gemset only if your team agreed on it.
Add .rvmrc to .gitignore so anyone can override .ruby-* files settings with .rvmrc.
For gems
Check in .ruby-version with ruby-1.8.7 only if your project still targets ruby 1.8.7, otherwise check it in only if your gem requires it.
Do not check in .ruby-gemset.
Checking in .rvmrc, .ruby-version or .ruby-gemset?
FOR:
Your project has different branches (say a RubyGems project supporting Ruby 1.8, 1.9 and 2.0 versions). Its better to check in this file, so that your developers don't have to keep on editing these files when they switch branches. The same doesn't apply for an application though, where you'll mostly be working on only one Ruby version.
Same case as above, but say you are running a CI server (say TeamCity/Jenkins/...) which automatically just runs rake spec for every check-in. You don't want to create separate build pipelines for each branch, just for the sake of having a separate rvm use ... for each branch. You just want the Ruby version selected automatically depending on the branch
You have tight control over the environment and all the developers. You either don't need or dictate that they use the same ruby and gemset
You are using Phusion Passenger or Capistrano, which automatically read .rvmrc files and chooses the right ruby for deployment/hosting
Also refer RVM Best Practices
AGAINST:
You can compile your own Ruby in RVM, with some experimental patches, and give it a custom name.
e.g. rvm install 1.9.3 --patch railsexpress,falcon --name ruby-1.9.3-perf
In the above example, I've installed Ruby 1.9.3 with some great speed up patches (btw they are awesome), but rather than calling it 1.9.3, I'm calling it my own name. I would say rvm use ruby-1.9.3-perf whenever I need this. In this case, if the project has its own .ruby-version, then it messes up my environment. In my project, these patches are standard and we actively recommend those. But how developers name the resultant compiled Ruby is up to them
Similarly, people use different gemsets. Some don't use gemsets at all. Some share the same gemset with different (but similar) ruby projects. Given this, again a single .ruby-gemset also doesn't work for everybody
Your project has an obscure ruby version which just says 1.9.3. Your developers first installed the latest Ruby 1.9.3-p329. But they later just update RVM/Rbenv (since they're working on other projects). Their .rvmrc or .ruby-version just breaks, since the latest version of Ruby registered in RVM/Rbenv just changed from ruby-1.9.3-p329 to .ruby-1.9.3-p362, and it will say ruby-1.9.3-p362 not installed. This scenario tends to happen often.
As long as you specify a proper full name for your Ruby version (including patch level), you should be OK. Let's say your project's .ruby-version says ruby-1.9.3-p329. Its easy to compile your own Ruby with all these patches, and still just custom name it ruby-1.9.3-329 just so that the config files will pick up this ruby instead of the standard ruby.
I would include .ruby-version - you and anyone else working on the project, along with your servers, should be using the same version of Ruby.
.ruby-gemset.... up to you, I think.
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
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