How do I rename a gemset? - ruby

Is there an RVM command to simply rename a gemset? I couldn't find it on the RVM site.

There is an RVM gemset rename command. I'm not sure when it was introduced but it is present in 1.0.16.
rvm gemset rename current_gemset_name new_gemset_name
As of RVM 1.21 or higher it will automatically switch you to the newly renamed gemset.
If you are on an older version of RVM you'll also need to switch to the newly created gemset, as follows:
rvm gemset use new_gemset_name
Running the command rvm gemset list will tell you the current gemset you are operating within.

I copied one with
rvm gemset copy <gemset_from> <gemset_dest>
and then deleted the previous one with
rvm gemset delete <gemset_from>

It's a RVM bug!
Solved in this pull request: https://github.com/wayneeseguin/rvm/issues/592#issuecomment-2705466
Commit: https://github.com/jwhitley/rvm/commit/619e5265927cf6c842ec3561345569af474ed20e

If you get the error that your gemset doesn't exist, but it exist you have to chose appropriate ruby version!
For example, if you have gemset ree#something-x and you current rvm (rvm current) is ruby-1.9.3-p194 then you have to execute
rvm use ree
and then
rvm gemset rename something-x something-y
It works with rvm version 1.16.17

Related

Switching between different ruby install and gemset using rvm

I recently installed ruby 2.0.0 using rvm and also created a new gemset for this install. I noticed that whenever I switch to ruby 1.9.3 (my old installed version), it knows to use the gemset that I created for that version of ruby.
My only problem is that when I switch to ruby 2.0 it does not know that it has to use the gemset that I created for that particular installation. Is there a way to setup rvm such that it automatically loads my gemset when the ruby version is switched.
In short, I am trying to avoid doing this
rvm use 2.0.0
rvm gemset use rails-4.0
You can create RVM alias:
rvm alias create rails-4.0 2.0.0#rails-4.0
use it with:
rvm rails-4.0
You can also set rails-4.0 gemset default to Ruby 2.0.0 with:
rvm use 2.0.0#rails-4.0 --default

How to check which gemset rbenv is using?

I use echo project-name > .rbenv-gemsets to create a new gemset for rbenv.
How do you check to see that it is using this gemset?
gem list is empty for the global gemset, so when I run it on the new gemset it doesn't tell me anything.
do a rbenv gemset active
If you've set up rbenv, and rbenv-gemset correctly, you will see the following output:
project-name global

how to make a gemset in RVM the default?

I'm trying to make a gemset the default whenever I start a new terminal in Mac OS X:
rvm use 1.9.3#rails3.2 --create --default
That seems to work, the rails3.2 gemset becomes the current gemset:
$ rvm gemset list
gemsets for ruby-1.9.3-p0 (found in /Users/me/.rvm/gems/ruby-1.9.3-p0)
global
=> rails3.2
$
But when I open up a new terminal, the rails3.2 gemset is no longer the current:
$ rvm gemset list
gemsets for ruby-1.9.3-p0 (found in /Users/me/.rvm/gems/ruby-1.9.3-p0)
global
rails3.2
$
What do I do?
Have you tried specifying rvm --default use after the gemset is created so passing:
rvm --default use ruby-1.9.3-p0#rails3.2
and then seeing if that sticks? Using create and default at the same time isn't something I've tried before, it's the only thing that strikes me as out of place.
Given the discussion below I'd offer this as a means for dealing with the problem. (Personally, I'd probably implode rvm and start over.) But, if you wanted to try to make a go of it with this install then I'd look at your .rvm folder, specifically in .rvm/environments/default which will contain all the environment variables exported for the default environment. Here you'll find rvm_gemset_name this may be set incorrectly and isn't updated for some reason (permissions?) or is set correctly in which case its some other environment issue. You could try manually setting it here in the file if its not correct.
You can use this command.
rvm use --default <ruby version>#<gemset name>
or
rvm --default use <ruby version>#<gemset name> or
rvm use <ruby version>#<gemset name> --default
Use following command to make a gemset as default.
rvm use <ruby version>#<gemset name> --default
eg.
rvm use 1.8.7-p370#mygemset --default
Interesting that nobody has mentioned rvm alias. Try your version-specific variation of this, works for me:
$ rvm alias create default ruby-2.3.0#rails_4_2_6
# me logs out, fetches another coffee
# me logs in
$ rvm list
rvm rubies
ruby-2.2.4 [ x86_64 ]
=* ruby-2.3.0 [ x86_64 ]
$ rvm gemset list
gemsets for ruby-2.3.0 (found in /home/aclarke/.rvm/gems/ruby-2.3.0)
(default)
global
=> rails_4_2_6
rubyracer related issue might as well come with libv8.
To get around this issue:
Step 1: Run the following command to uninstall any existing installation of libv8:
gem uninstall libv8
Install rubyracer by running the following command:
gem install therubyracer -v 0.12.2
Install libv8 by running the following command:
gem install libv8 -v 3.16.14.15 -- --with-system-v8
Try bundle install now:
bundle install
You can use this command
$ rvm use rubyversion#gemsetname --create --ruby-version
For example :
ruby version = ruby-2.1.2
gemset name = gem320
It would be
$ rvm use ruby-2.1.2#gem320 --create --ruby-version.
Even if you open other tab also, it will preserve the settings.

RVM: How to use gems from a different ruby?

I have been using RVM to manage my Rubies and gems.
When I first installed RVM, the Ruby version that I installed was 1.9.2-p0. I recently installed Ruby 1.9.2-p136, which created a new Ruby in the RVM.
My problem is I want to use the latest version of Ruby but all of the gems I installed were installed under the 1.9.2-p0 directory, because RVM keeps gems completely separate between Rubies, and I want to be able to use those gems with my new version, p-136 without having to reinstall them all.
Is there a way I can get my gems from my p-0 Ruby to work with my p-136 Ruby?
You can use copy in rvm
$ rvm gemset copy 1.9.2-p0 1.9.2-p136
See more about the rvm copy command
This is the fastest way to get your gems moved over and it wont reinstall everything, just copy them over. But once you've got that squared away I'd do as the others are suggesting and start using gemsets. It's a nice way to group the gems you use in your projects.
This might help: http://rvm.io/gemsets/initial/
Basically, if you setup a global gemset configuration, those gems will be used for every ruby version you install.
You need to check out gemsets and export your current gems.
rvm gemset export
Read the gemset docs for more information.
You can copy a gemset from one ruby to another.
rvm copy
$ rvm gemset copy 2.1.1#rails4 2.1.2#rails4

RVM: Uninstalling all gems of a gemset

I have global gems and various gemsets. I want to remove all gems of a gemset. Is there a way do to this, besides uninstalling the gemset?
Use the gemset empty command:
rvm gemset empty mygems
This command removes all the ruby gems installed locally in 1-step
Works well in Ubuntu 10.10
gem list | cut -d" " -f1 | xargs gem uninstall -aIx
PS - removes all local gems. Use sudo accordingly.
you can also use rvm --force gemset empty
rvm gemset empty <gemset name>
This will remove all gems from your mentioned gemset.
rvm gemset empty <gemset> works, but only if you specify a gemset name.
If you want to empty the default gemset, you need to pass an empty string for the gemset name.
rvm gemset empty mygems ""
Isn't removing all the gems out of a gemset essentially the same operation as deleting a gemset and then adding it back? Why not just do this:
$ rvm gemset mygemset
$ rvm gemset delete mygemset
$ rvm gemset create mygemset
This is the safest way to uninstalling all gems of a gemset
Step 1
If you gem version is less then 2.1.
gem update --system
gem --version
Step 2
gem uninstall --all
references

Resources