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)
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'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.
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 installed Rails 3 by following this gist: http://gist.github.com/296055
But when I try "rails" in terminal I get the following error:
/Users/yves/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.0/lib/rails: Is a directory - /Users/yves/.rvm/gems/ruby-1.9.2-head/gems/activerecord-3.0.0/lib/rails (Errno::EISDIR)
from /usr/bin/rails:19:in `load'
from /usr/bin/rails:19
Any ideas?
UPDATE
Ok, I figured out something. I can run the correct rails by going directly to the right executable:
/Users/yves/.rvm/gems/ruby-1.9.2-head/gems/rails-3.0.0/bin/rails
Apparantly my "rails" command is still linked another version, the one in usr/local/bin
How can I change this?
Check out my answer on this other question:
(if this works for you, we should mark this as a duplicate question. But I don't have enough points to do that myself)
--
Older versions of rvm had a bug that can cause your ruby versions to get crosswired because the OS can cache executable paths for the which command (particularly if you are using zsh). See this long, detailed, mind blowing post by Yehuda Katz on the subject.
What I had to do this morning:
rvm update && rvm reload # update rvm
rvm gemset delete rails3 # delete old gemset
rvm install 1.9.2
rvm use 1.9.2
rvm gemset create rails3
rvm use 1.9.2#rails3
which ruby # check to be sure the ruby interpretter is properly set to 1.9.2
hash -r # if ruby interpretter is not pointing to 1.9.2
gem install rails
which rails # check to be sure we are using rvm version of rails
I followed this article and was able to install everything. The article is in Russian, but you should be able to translate it to desired language via Google translate.
I bumped into 'no ssl' error but this article explains how to resolve it as well (at the bottom).
My setup now is:
RVM
Ruby 1.8.7 + Rails 2.3.8
Ruby 1.9.2 + Rails 3.0.0
Hope this will help you.
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.