I'm not clearly understanding the role of; RVM, RubyGems, Gemsets, Homebrew & Bundler, how they interact together and how I should use them to manage my envrionment, different applications, different Ruby versions, different Rails versions and everything's respective dependencies.
I've been happily coding using Ruby 2.3 and rails 5.0.3 for latest apps and older versions for some others, but through luck more than planning have not had any environment issues to date. I am just about to start the Agile Web Development with Rails 5 and I'm trying to get environment set up to match the tutorial. This leads me to needing to better understand RVM & Gemsets, RubyGems, Bundler, Homebrew so that I can now manage different Ruby and Rails versions on my machine.
First step has been to update my Ruby version which was 2.3.0 via rvm install ruby-2.4.2, installed successfully.
This leads me to realise that despite having various Rails versions on my machine, 'linked' to older versions of Ruby, I don't have any Rails versions 'linked' to my new Ruby v2.4.2.
Question no. 1) Surely I don't have to actually download another copy of my desired Rails version for this new Ruby v2.4.2? Can I not somehow 'link' the previously installed Rails version to this new Ruby v2.4.2?
Here's what rvm gemset list_all gives;
gemsets for ruby-2.2.2 (found in /Users/jamesbkemp/.rvm/gems/ruby-2.2.2)
=> (default)
global
gemsets for ruby-2.3.0 (found in /Users/jamesbkemp/.rvm/gems/ruby-2.3.0)
=> (default)
global
gemsets for ruby-2.4.2 (found in /Users/jamesbkemp/.rvm/gems/ruby-2.4.2)
=> (default)
global
Question no. 2) Does RVM's 'gemsets' do the same thing as Bundler? ie do I use only one or the other? In my case I've been using Bundler, so would rather stick with that if it's a case of either or.
Question no. 3) So that I can better understand these environment management tools can anyone give me a high level overview of what I should be using RVM & Gemsets, HomeBrew & Bundler for, specifically which should be used to update what and where do the boundaries lie between each tool.
Thank you.
My workflow working with rvm is as follow
1 - I install a ruby version with $ rvm install 2.3.1
2 - Select the ruby version $ rvm use 2.3.1
3 - Now I create a gemset for encapsulate gem versions in a gemset avoiding versions conflicts with other apps, so $ rvm gemset create my_app
4 - Now I select the gemset $ rvm use 2.3.1#my_app
5 - Install a Rails version $ gem install rails -v 5.0.3
6 - Create the app, $ rails new my_app
Now you have your rails and gems installed on my_app gemset.
7 - Finally, I explicit in the app the ruby version and gemset used adding, in the my_app root path, a .ruby-version file containing 2.3.1 and a .ruby-gemset file containing my_app, so when I enter to my_app root path, rvm knows that it must change automatically to 2.3.1#my_app gemset and you donĀ“t need to type $ rvm use 2.3.1#my_app each time.
Answering to your first question, maybe you have rails installed but only in one ruby global gemset -a global default gemset-, so if you install a new ruby version you must install again the rails gem in it. I recommend to create a gemset for each app because reduce gems collision troubles if you have different apps.
Related
I first used rbenv to install ruby ver 2.2 and Rails ver 4.2 on Linux CentOS 7, then used rvm to install ruby ver 2.4 and rails ver 5.2. Is there a way to switch between these easily or do they both have to be installed using the same method for this to work?
Better you can use rvm. Rvm is the better tool to switch between many versions with the command
rvm use ruby-2.5.1 or rvm use 2.5.1
For list out all rvm just use
rvm list
within rvm, you can manage the versions nicely no need of rbenv here.
I prefer RVM, it's easy to switch between version, also you can use multiple rails version for that ruby easily
install rvm, install ruby and create a gemset with rvm use 2.4#rails_5_2 --create will create a gemset with name rails_5_2
for switching between versions. I use .ruby-version and .ruby-gemset files in my project so i don't need to specify version all the time
in the .ruby-version file write the ruby version
2.4
and inside ruby-gemset write gemset name
rails_5_2
so whenever you will run the project it takes ruby and rails version from there
you can create this two file manually or you can run this command in terminal from your application directory which will create this two files
rvm --ruby-version use 2.4#rails_5_2
I fixed this by removing RVM and installing the newer versions with rbenv instead. Having both versions installed with the same method allowed it to be easy to switch when needed. The shims automatically use the correct Rails versions for each project respectively. As far as I can tell, the Rails versions are locked in with whichever one you started the project with. You can switch the Ruby version for each project by using:
# rbenv local 2.4.1
I chose rbenv over rvm because I read several articles of people praising rbenv's lightweight approach and ease of use over rvm.
NOTE: the "#" character is the beginning of the command line in Linux CentOS 7, NOT a character that you type in.
EDIT: Thank you guys for the recommendations, though. It got me to look more into using rbenv vs. rvm.
I currently have several Rails applications running version 3.2.13 that use Ruby 1.9.3. I plan to eventually upgrade my current applications to Rails 4.0 then upgrade Ruby to 2.0. I need to time the conversion to Ruby 2.0 carefully since from my understanding Phusion Passenger will only handle one version of Ruby without some nose bleeding solutions which I do not plan to attempt to implement at this point.
I currently use one gemset for all my Rails applications. I would like to convert my Rails applications one by one from 3.2.13 to the current version of Rails 4.0 at some point. When I have tried to update one of my applications to a newer version of Rails I was told I had to do a update rails command.
What I want to do is to be able to run some of my applications using Rails 3.2.13 and others using Rails 4.0 until I am sure they will all run properly under Rails 4.0. Once I do this I will review the differences between Ruby 1.9.3 (if any) and upgrade all of them to use Rails 2.0. At this point I understand that I would just create the gemset for 2.0.0 or whatever the latest stable version of Ruby 2 is.
I have done web searches and checked the RVM website. I understand how the gemsets are assigned to the version of Ruby you want to run. However I'm not seeing anything about using gemsets with the same version of Ruby but using different versions of Rails or other combinations of gems on the same machine for different applications. Can this be done?
Any help would be appreciated.
Take a closer look! ;)
First, create a new gemset with a name corresponding to your project
https://rvm.io/gemsets/creating/
ex: rvm gemset create project_name
Then create/edit .rvmrc file in project directory: rvm use 1.9.3#project_name
One pitfall is that if you execute following commands
cd some_project
cd ../other_project
and other_project doesn't have gemset specified you'll stay in some_project gemset. To avoid that you can create .rvmrc file with default gemset in your "projects" directory (if you have one)
Project Folder
|___Gemfile
|__.ruby-gemset
|__.ruby-version
Gemfile with all the required gems mention in your project folder
.ruby-gemset should have gem set name like sample-gemset
.ruby-version file should have specific ruby version (e.g 2.0)
rvm gemset list
it will show gem set created with sample-gemset and do the
bundle install
which will install all the specific gems for this project under sample-gemset,
same you can do for other project to create other gem set, in this way you can maintain different rails/gems and ruby version for different projects with rvm.
Your Gemfile.lock nails down which version of every gem you use - you don't need to worry about gemsets.
bundle install will always install the correct versions and your app will always use the versions in Gemfile.lock, even if there are other versions floating around
I'm trying to keep along with the Tekpub Build your own blog on rails screencast. I'm still very much a ruby novice and the problem is that I have Rails 3 installed while Rob uses an older version (Of the top of my head: version 2.3.2).
I know how to get that version of rails with gem install rails --version=2.3.2 but when I type rails new the version of the application is rails 3. How do I make this particular app work with the older version? I know this has something to do with rvm but I have no idea how to do anything but the basic rvm use operation.
Try,
rvm use <ruby version>
rvm gemset create rails2.3.2
rvm <ruby version>#rails2.3.2
gem install rails --version=2.3.2
Finally the syntax to create a new rails app in older versions of rails was just:
rails <appanme>
For more information about gemsets:
RVM: Named Gem Sets
This will install Ruby 1.8.7 and then create a gemset that will contain only a specific set of gems:
rvm install 1.8.7
rvm --create use 1.8.7#old_rails
gem install rails --version=2.3.2
Whenever you want to use this after the first time just:
rvm use 1.8.7#old_rails
.rvmrc files are really useful for automatically managing different sets of Ruby versions and gems. If you create file called .rvmrc in the project directory and put this line in it:
rvm --create use 1.8.7#old_rails
Then every time you cd into that directory RVM will switch to Ruby 1.8.7 and the gemset "old_rails". Have a look at the docs for .rvmrc here: http://rvm.beginrescueend.com/workflow/rvmrc/
Of course you can change "1.8.7" for "1.8.6", "1.8.7-p249", "ree-1.8.7-2010.02" or any other Ruby version you like, I just assumed that you would want 1.8.7.
Have a look at RVM (Ruby Version Manager)
Is there a way to install a Rails 2.3.10 app if I have Rails 3.0.3 installed on my machine?
for example i'd like to start my server with ruby script/server instead of rails server.
thx
Two main ways:
Bundler: you can create a Gemfile and use bundler to silo the gems for each of your installations. The drawback to this one is that you'll probably have to use "bundle exec command" whenever you want to run a command for the version of rails you're using, such as spec or cucumber
RVM: using RVM you can use not only different versions of Ruby, but also separate gemsets within a version of Ruby. I personally use this method most of the time, creating a gemset called "rails3" and "rails2" (or sometimes I use a gemset for the application) with the relevant gem versions in it. You can have as many gemsets as you want and switch between them. Stick a .rvmrc file in the root of your application, and rvm will switch the version of ruby and your gemset for you automatically.
So I want to create environments for rails 3 and rails 2.1.1
How do I do this?
Where do I look for the various versions of rails?
I get an error when I try:
rvm 1.9.2-head
ruby ruby-1.9.2-head is not installed.
I just followed what I read on: http://rvm.beginrescueend.com/gemsets/creating/
Yes, gemsets are ideal for this. I use gemsets for this too.
First you have to create the gemset:
rvm gemset create your-project-name
then use the gemset:
rvm gemset use your-project-name
When you do this, all your gems are unreachable, you can get them back by using rvm gemset use, which will return to the default gemset (unnamed).
Inside your gemset, you will have to reinstall all needed gems. If you are using bundler, it is as simple as
bundle install
The advantage of using gemsets is that your gems are cleanly seperated. For instance, i ran into trouble with spec/rspec scripts when using both rails2 and rails3 together. With gemsets i no longer have any problems. Using an .rvmrc file per project, even the selection of the correct gemset is automatic, and i can configure my project in rubymine to use the correct gemset too. Awesome :)
Rvm is for different versions of Ruby not rails. You can potentially have every version of rails installed on one version of ruby. The application itself will in it's Gemfile or config specify what version of rails you are using.