I am wondering how RVM manages the gem/gemsets. For instance, I have by default been using ruby 1.9.2#global and installed rails 3.1.3 in this environment. Later I copied a rails project from other, which is based on rails 3.0.10. By cd into the folder, I ran rails -v, it recommended me to run bundle install. I did so. After this, lots of gems were installed including rails 3.0.10. But when I do rvm 1.9.2 do gemset list, there is no new gemset( this is expected though). Then how do I manage the two versions of rails?
Thank you in advance
You can have more than one path into your Gem.path.
Try running ruby -r rubygems -e "p Gem.path" and check the output, you'll see that both #global and your current gemset are included.
Rubygems use the $GEM_PATH variable to figure out where to look/install gems, and that's one of the things RVM sets when you change a ruby version/gemset.
Also, it might be worth to look at a few environment variables RVM sets. Run this:
env | grep -i rvm||path
There might be a few extra ones (including $PATH), but you'll general you'll see a lot of RVM environment variables.
That's why some people like rbenv, a simpler way to manage ruby versions.
Related
Working with this repo, which requires ruby 2.1.1 and rails 4.1. I am using RVM, and I have downloaded ruby 2.1.1, but I am getting this error when I type rails -v. I feel like I need to start completely over, but do you see anything below that may have a relatively simple solution?
When I type rails -v, I get this error:
/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/dependency.rb:298:in to_specs': Could not find 'railties' (>= 0) among 14 total gem(s) (Gem::LoadError)
When I type in ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
Bash_Profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM$
RVM Gemset List
gemsets for ruby-2.1.1 (found in /Users/me/.rvm/gems/ruby-2.1.1)
=> (default)
demo
global
myapp
rails
rails4.1
Try to run these commands:
rvm use 2.1.1#rails-devise --create
bundle install
rails -v
evan: but not when I generate my own app because it gives me an error before I can create it.
Lets discuss some basic concepts of RVM, that can help you:
Every project should contain its own gemset. Repo contains two special files in root folder:
.ruby-gemset - contains unique, project-specified name of gemset
.ruby-version - Ruby version number, to see list of available: rvm list
These files should be placed in root folder of every project on your computer.
When you open project from the linux Terminal, rvm scan for these two files, read them, and activates needed ruby version and loads necessary gems automatically.
Note: each rvm session is alive in current Terminal session only. You should reactivate it for each Terminal session separately.
If current gemset name is not specified, RVM uses default rvm gemset (unnamed gemset).
I uses default gemset for my default projects, when I need quickly create something temporary. But I noticed, that default gemsets of beginners reminds a dump of different unsystematic gems. Some of them can relate to same Gem modules, but with different versions.
Such kind of versioning, may leads to different strange errors and problems, what happened with you. If you want use a default gems set (I suppose you is a NOT rails-developer, based on your profile), open your project directory, and perform in terminal:
rvm gemset empty ''
rvm use #default --default
bundle install
I'm having difficulty understanding RVM per project gemsets. I've installed RVM and the 1.9.2 and 1.8.7 rubies, as per http://beginrescueend.com/interpreters/ruby/ , and when I want to start a new project, I've been
cd ~/Code
rvm use 1.9.2
rvm gemset create test1
rvm gemset use test1
gem install rails
But this takes a long time! (installing rails). I then rails new test1; cd test1
I'm really unsure with the correct workflow. If I'm making a new app to test in, I don't want to have to wait for rails to install.
It seems from http://beginrescueend.com/gemsets/basics/ that I can create a rails gemset, but then how do I create a per project gemset?
Edit:
If I'm going to using multiple ruby/rails versions, should I create a gemset, say 1.9.2#rails313, then rails new blah, put 1.9.2#rails313 in blah/.rvmrc , and if I need to later on, create a blah gemset?
A gemset is just a container you can use to keep gems separate from each other.
The Big Idea: creating a gemset per project allows you to change gems (and gem versions) for one project without breaking all your other projects. Each project need only worry about its own gems. This is a Good Idea, and the wait time for installing large gems like Rails is usually worth it.
That said, if you're going to use the same version of Rails across all your projects and want to save time, you can install rails (and maybe rake as well) in the 'global' gemset - these gems are available in all gemsets for that version of ruby.
Assuming you already have a test1 gemset:
$ rvm gemset use global
$ gem install rails
$ gem install rake
$ rvm gemset use test1
$ rails test1
Once I wrote a simple blog post on how to use RVM with gem sets, this might be helpful to you.
UPDATE: As the link above is dead, I believe it is in another location here.
I have both ruby and rails installed in:
/usr/local/bin/ruby
/usr/bin/ruby
/usr/local/bin/ruby
This is causing problems when I try to run certains commands like ruby script/console
How do I remove some of these installations of both ruby and rails?
RVM will help you for sure. Check out RVM here
Preventing this kind of situations is the very role of RVM and it's gemsets.
I encourage you to check it out.
There are a few options. First one would be to get your ruby system install in good order. There is no harm in renaming removing those multiple ruby file in your diverse bin folders. Get the stable release of 1.9.2 and gem install whatever you need then. Googling around to fill the gaps you may have here
Quick and dirty you can do:
Get the latest stable release of ruby 1.9.2, compile it on your system, I suppose the ruby that is under /usr/bin is the system's and you are using macosx. The one located in /usr/local/bin is probably something you installed yourself and even maybe you don't even need to reinstall ruby 1.9.2. If that's so get you .bashrc in proper order by making sure /usr/local/bin comes before /usr/bin and you won't have to worry so much about which version you might be using. Create a ~/.bash_profile and put this in.
export PATH="/usr/local/bin:$PATH"
Expected output (more or less):
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/texbin
Others mentioned RVM. I used it, but I don't use it on a production server, I prefer a single sane ruby install to RVM. There is also rbenv and is seems much saner.
Final thought play around in your system remove symlink stuff, set your PATH variable or use RVM/rbenv.
Managing Ruby: Moving From RVM to rbenv
It's time to switch over, http://cantina.co/2011/10/08/managing-ruby-moving-from-rvm-to-rbenv/
I am exploring the world of Ruby and RVM. I am going through a lot of documentation and trying out RVM, but I am a bit confused about the entire work flow. I am writing down the workflow as I understand it. Can someone please take a look and see if this understanding is correct?
I am using a Mac.
RVM is essentially a script that allows us to manage Ruby environments for development purposes.
RVM allows switching between different versions of Ruby with rvm use 1.9.2.
To use a particular gemset with the current Ruby version, we need to create a gemset using
rvm --create gemset rails235
Install the gem using gem install rails -v=2.3.5
Q: What happens if I did gem install rails -v=2.3.5 prior to creating a gemset? Will there be two copies of the same Rails installed under RVM's Ruby 1.9.2?
Q: What happens if I install 2.3.5 and 3.1.0 prior to creating gemsets and then create a gemset for each version?
Q: where does rvmrc come into picture in the whole story?
Any other information that helps me get this straight is extremely helpful.
#Kiran, this is in reference to your comment above. When you install a different version of ruby with rvm, it'll add to this list:
$ rvm list
rvm rubies
=> ruby-1.9.2-p290 [ i386 ]
On my system, I've only got one version running (for now). This helps too
$ rvm gemset list
gemsets for ruby-1.9.2-p290 (found in /Users/mike/.rvm/gems/ruby-1.9.2-p290)
global
=> mg_diaspora
rails3
railscasts
ruby
sorcery
The practice is to install common gems into your global gemset and create/use sets for everything else. I tend to keep pry and others in the global gemset. As Mike K. said, you'd never do #2; if you did do such a thing, I would imagine global having priority.
#3 .rvmrc
You can do things like this in the file:
rvm use 1.9.2#rails3 --create
This will ensure whenever you 'cd' into the directory, it'll switch to 1.9.2 and it's 'rails3' gemset; the following attribute ensures the gemset will be created if it doesn't already exist.
Update
Ex: if I say rvm use 1.9.2#rails3 --create how does this pick the version of rails3.1.0 gem
Because by the time this rails3 gemset is created I already have 2 versions of rails gems?
That's easy - when you run bundle install it creates a Gemfile.lock; this essentially 'locks' the gems that your application is set to use. You've never require two different versions of rails in a single Gemfile anyways - that's just ridiculous =)
1) Rvm automatically creates an #global gemset per interpeter so if you did what you state in the first question you'd have a 2.3.5 in the global gemset.
2) I'm not sure why you would do this.
3) rvmrc is just where you can specify environment info like bashrc, i use it to specify my default architecture for instance. It gets read when rvm gets sourced in your profile.
Basically global is a mix-in for all other gemsets under a specific interpreter. So, if you put rake and say bundler into the global gemset, and then create and enable your own gemset under that specific ruby, it will have both the gems you install in that gemset AND global.
You will see it as a single gemset though. Also, if you attempt to delete a gem that is in global while still in, say, mygemset you will not be able to delete it. This is to protect other gemsets from having gems mixed in from global that they rely on from being removed. You would have to either explicitly change to global or execute something like
rvm 1.9.2-p290#global exec gem uninstall rake -v='0.9.2'
Also, bear in mind that there is a significant difference between 'default' and 'global'. The 'default' gemset is not really a gemset perse. This is selected when you do something like
rvm use 1.9.2
Notice you did not select a gemset in the above command. This is where default lives and plays. When no gemset is selected, default becomes active and global totally disappears. To load default, you would modify $rvm_path/gemsets/default.gems as these are the list of gems to be installed into each interpreter's 'default' set. The other file there is 'global.gems'. This is used as you would surmise; to load a default set of gems whenever you install a new interpreter under RVM into the global gemset, which is shared by all other gemsets for that Ruby, but not for 'default'.
Please see https://rvm.beginrescueend.com/gemsets/basics/ for more information.
I have used the same script to setup ruby and gems via rvm for two users on the same machine. I have confirmed with rvm --version that I'm using the same version and things seem to be installing identically.
However, on one my $GEM_PATH is being set properly, on the other both $GEM_PATH and $GEM_HOME are both blank - I have confirmed this both by echo $GEM_PATH and within a ruby script reading ENV['GEM_PATH']
Is RVM meant to set $GEM_PATH? If so, any ideas why it hasn't for me?
Are you sure both machines are running the same set of ruby and gems?
If the first is running version a of ruby and version b of gems and the second one is running the system versions (very likely on OS X) then the second machine may have different gem paths.
Make sure to do
rvm use _version_you_want_
in both machines!