What I did:
I installed rails by mistake to the wrong gemset.
$ rvm use 1.9.3
Using /home/username/.rvm/gems/ruby-1.9.3-p125
$ gem env gemdir
/home/username/.rvm/gems/ruby-1.9.3-p125
$ gem install rails
It should have gone into the global gemset.
$ rvm use 1.9.3
Using /home/username/.rvm/gems/ruby-1.9.3-p125
$ rvm gemset use global
Using ruby-1.9.3-p125 with gemset global
$ gem env gemdir
/home/username/.rvm/gems/ruby-1.9.3-p125#global
$ gem install rails
Questions:
How can I uninstall the whole list of gems installed with rails as well as rdoc and ri without affecting other gems installed in the same gemset? Can I also clean the cache/ folder in the same step?
As far as I understood it is best practice to install common gems
into the global gemset, while project specific gems will go into
the specific gemset of that project. Is that correct?
By the way, what is the "wrong" gemset under /home/username/.rvm/gems/ruby-1.9.3-p125 good for anyways?
I am aware of similar questions like these.
Uninstall Rails 3 with dependencies?
Uninstalling rails and gems, getting error "cannot uninstall, check 'gem list -d ...'
How to completely uninstall rails 3.0.0.beta3 and all its dependencies?
How do I completely uninstall rails, ruby and rubygems?
Though, I do not want to reinstall or update rails. I simply want to remove it from that particular gemset.
Approximation / question 1:
I only found an answer to the first question. Thus, it does not remove rails and its dependencies but all gems. This is what I did following the example given. I left off the name since there is no specific name, as far as I understand.
rvm use 1.9.3
Using /home/username/.rvm/gems/ruby-1.9.3-p125
rvm gemset empty
This removed the files under doc/ and gems/. However, the cache/ folder is still filled.
How can I uninstall the whole list of gems as well as rdoc and ri?
gem uninstall gemname1 gemname2 ...
will also remove ri and rdoc, just list the gem's names without any commas. (you can list all be using "gem list")
UPDATE:
"rvm gemset empty" works faster indeed.
As far as I understood it is best practice to install common gems into the global gemset, while project specific gems will go into the specific gemset of that project. Is that correct?
Yes, it's correct. Global gemset is reached by all Gemsets from the same Ruby version.
By the way, what is the "wrong" gemset under /home/username/.rvm/gems/ruby-1.9.3-p125 good for anyways?
I think it's global. Try "gemset list" to which one is that. There will be a = sign before the current one in use and a > sign before default gemset.
I think maybe your gemset is not wrong, it's probably how you want it. Try to make a new Gemset, and change to it and list all gems, probably you're gonna see all your gems.
You can remove a whole gemset anytime (except global) by:
gemset delete gemsetname
Also you might want to install rails without ri and rdoc:
gem install rails --no-ri --no-rdoc
Related
I would like to understand a very basic concept in Ruby on Rails. Everytime I create a new Rails application, I used to create a gemset and then install gems to that gemset. Once my friend asked me why I do that and I failed to make him understand very clearly.
Is it because if I have 2 projects under the same Ruby version and if both need different versions of a particular gem? Suppose, both are using the default gemset, it can't install both versions of this gem to the default gemset as it would cause a conflict? Please correct me if am wrong.
Gemsets are useful to make independent rails application, where other rails application (with the same ruby version) does not share gems among each other (as it does gem bundler)
For now, using of gemsets is overhead, because:
gemsets decreases download gem speed
gemsets increases space on a hard drive
gem bundler handles dependencies well
if your gems will be corrupted, you can restore them with gem pristine --all
development and production environments go towards Docker with its own independent layers
Just don't use gemsets
By gemset you mean RVM Gemsets right? RVM Gemset compartmentalized ruby setups, from the system and each other. This is very helpful if you have multiple Rails project for example. Each project might require different versions of same gem(s).
However, if you are using Bundler you don't need to use RVM Gemsets. Prepending any command with bundle exec will execute it in the context of the project's Gemfile.
References
Related question on Stack Overflow
How to use Bundler instead of RVM Gemsets
It's very interesting questin.
you can consider gemset is = kind of space in hard drive
I will show you full process.
if you have more then one projects with different ruby versions then we need to use rvm to avoid conflicts.
so for that we need to use RVM (Ruby version manager).
Steps:
1) install rvm
2) after installing rvm we need to use ruby version
ex : if you have more then one ruby installed in your system then chose one of them
rvm --default use version
For example you have 2 projects with ruby 1.9.X and other project with 2.0.X
So in this situation if you are not using rvm then it may chance to get conflicts so we should create new gemset like bellow.
Ex:
rvm gemset create demo
rvm gemset use demo
so currently we are pointing to gemset demo
now we already install ruby but we do not have rails in this gem so we must install rails and other gems in it.
so the conclusion is that we use gemset for avoid conflict between to ruby versions.
How do I safely upgrade my ruby on rails app to use a new ruby version, using rvm?
Suppose your app is my_app and you are using ruby version a.b.c and want to go to ruby version x.y.z.
Step 0
Before starting, make sure you have the up to date version of rvm
rvm get stable
rvm reload
Step 1
First if you do not have a gemset for your current ruby version create one and make it the default. This gives you an easy way to go back if your upgrade breaks your tests. If you do not want to do this, go to step 2.
rvm gemset create my_app_abc
The switch to that gemset and install the gems into that gemset, and make it the default gemset for the directory
rvm a.b.c#my_app_abc
bundle
rvm --ruby-version use a.b.c#my_app_abc
Step 2
Now upgrade to the new ruby version and create a gemset for it.
rvm install x.y.z
rvm use x.y.z
rvm gemset create my_app_xyz
rvm x.y.z#my_app_xyz
It is considered best practice to specify the ruby version in your Gemfile so
make sure you have ruby 'x.y.z' at the top of your Gemfile. Then
gem install bundle
bundle
This is where the fun can start, you may get errors at this point and use a combination of following the error instructions or googling for help, etc to solve them. When you can bundle successfully, then run all your tests.
When your tests have all passed, then you have successfuly upgraded. If you get stuck, you can go back to your old installation, using rvm a.b.c#my_app_abc.
Once you are happy with your new installation then do
rvm --ruby-version use x.y.z#my_app_xyz
to make this the default setup for this app. This means when you change into this app from other projects, it will automatically load ruby version x.y.z and the corresponding gemset.
According to this blog, if you always precede commands by bundle exec you do not need to use gemsets. In that case, you would simply do
rvm --ruby-version use x.y.z
I got confused of some Rails' concepts like: gemset, rubygems, bundler . I have following three questions:
1. After I installed the RVM tool, what are the correct steps to setup the development enviroment for creating a rails project (say rails v2.3 project)
2. What is the difference between "gem install XXX" and "bundle install"? Can I understand it in the way that "bundle install" install all gems needed in the app at once while "gem install XXX" only install the specified "XXX" gem ? Are there any other difference? Why not use bundler to install specific rails then?
3. If I want to use rails v3.0 for project_one, and use rails v2.3 for project_two. How to create the two projects with the specific rails versions? How about different ruby versions for different projects? Do I only need to specify the needed version in Gemfile or install the needed version under the project path?
RVM allows you to create different gemsets alongside different ruby versions.
You can install different versions of ruby with rvm install.
rvm install 1.8.7
rvm install 1.9.2
rvm list known will tell you the available ruby implementations you can install.
Say, you have two projects: project_one and project_two, and both of them have different gem dependencies. So you'll want to create two empty gemsets with, say, Ruby 1.9.2.
rvm gemset create 1.9.2#project_one
rvm gemset create 1.9.2#project_two
To use project_two's gemset, you can use rvm use to select the gemset.
rvm use 1.9.2#project_two
You can also add the above command into a file called .rvmrc in the root path of your rails application, which rvm will load automatically whenever you cd into the app's root directory.
If you want to use Rails 2.3.8 for project_one,
rvm use 1.9.2#project_one
gem install rails -v 2.3.8
and Rails 3.1.0 for project_two,
rvm use 1.9.2#project_two
gem install rails -v 3.1.0
The difference between gem install and bundle install is that gem install installs only the specified gem into your gemset, while bundle install installs all the gems located in your app's Gemfile.
1) If you have a rvm setup I propose add in in your app file .rvmrc
and in that file:
rvm --create ree-1.8.7-2011.03#myappname
This will alway use specify version of ruby (in that case 'ree-1.8.7-2011.03') and all gems will be installed in rvm gemset named: myappname. This file will always make sure every time you go to that folder from bash_console it will point rvm to correct environment.
2) If you have rvm setup then:
gem install XXX creates gem in specify rvm gemset or if not global rvm gemset
sudo gem install XXX will add gems to you Global gems
Like you said, you should always use Bundle install, and group gems for development,test, production.
3) This can achieve like I said in point 1) just create this file in your app
In my rails application
ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
When I run
rvm gemset list
It specifies my gemset which i'm using
global
=> blackapp
now i do bundle install and gems are installed successfully.when i do gem list, it shows * LOCAL GEMS * as empty.When i run rvm gem list it shows all the gems.So what could be the reason that gem list is not working.
I think I used bundle pack and that could be the reason as it shows .
Your bundle is complete! It was installed into ./vendor/bundle
How to overcome this?
bundle install will install the gems to the vendor/cache directory within a rails app, which does not install them in the gems directory. To list the gems installed by bundler, use bundle list
use gem list --local instead of using gem list local
you also have to make sure you have selected your specific gemset you want the gems installed into. I see that you did this, but this is the number one reason for 'disappearing' gems. People forget to select the gemset prior to doing the install of gems, then end up installed in the 'default' gemset (which is used when no gemset is selected), and then they select their gemset and wonder why they're not there.
Also, do NOT use rvm to install to system. System rubies are NOT managed at ALL by RVm and the only reason why RVM supports
rvm use system
is simply to allow people to select the system ruby. RVM is not and will not be responsible for changes to the system ruby and its environment as this is usually managed by the OS's package manager. Using RVM to manage this is a Bad Idea(Tm) as a result.
I want to switch between rails 2.3.10 as the "active" gem for my OS, so that I can invoke it at the command line.
Is it possible to do this? I'm not using rvm. Maybe it's time to start.
I tried gem install rails --version=2.3.10, but that just makes sure that version of the gem is installed, it doesn't put it in /usr/bin/rails.
(I do already use bundler for my apps -- but haven't needed any precise control over gems at the OS level until now)
If your problem is to run binaries of a certain version, then:
rails --version # => the latest version
rails _2.3.10_ --version # => Rails 2.3.10
This pattern (gem-binary _gem-version_) works for any gem binary.
Use RVM
RVM allows you to manage different versions of Ruby and Gems. You can install a version of ruby using, for example
rvm install 1.9.2
You can then use it using:
rvm use 1.9.2
Use specific gems on a per project basis with gemsets.
If you want further namespacing you can set up gemsets; directories which will contain specific gems for a specific project.
rvm gemset create myproject
then you can use them like so:
rvm use 1.9.2#myproject
Automation
To automate the process of switching gems, pop .ruby-version and .ruby-gemset files in your project root. Pop the version of Ruby and name of the gemset you want to use inside them and RVM wil select the correct gemset when you cd into your project directory.
Installing gems into your gemset
Install your gems into your gemset in the usual way using bundler if you are using it:
bundle install
or just using the regular old:
gem install mygem
The gems will go in the right gemset.
RVM Alternatives
You might also want to check out rbenv, which does similar job.
You can use RVM
Then you can also use Bundler afterwards, which manages gem dependencies fine.
In your Gemfile
gem "rails", "2.3.10"
and in your application
require 'rubygems'
require 'bundler/setup'
and you're done.
EDIT: Just saw your RVM mention in the post. Definitely the way to go.
You're going to want to install RVM -- it's an amazing package that will let you manage different Rubys and different sets of gems on the same machine. You can switch back and forth with total ease.
Here's the installation guide: http://rvm.beginrescueend.com/rvm/install/
Once you got everything get up, you can see all of your installed rubys at the command line with with rvm list, and switch with rvm use ruby-head, for example. RVM keeps the gems on each ruby separate, which should help with your question.