rvm gemset

http://stackoverflow.com/questions/4693445/rvm-uninstalling-all-gems-of-a-gemset

先把gem清空,再清除gemset

```
lalala12:~/workspace (master) $ rvm gemset list

gemsets for ruby-2.3.0 (found in /usr/local/rvm/gems/ruby-2.3.0)
=> (default)
   global
   rails5
   test

```

gemset的使用 https://ruby-china.org/topics/13761



```
lalala12:~/workspace (master) $ rvm gemset list                                                                                        

gemsets for ruby-2.3.0 (found in /usr/local/rvm/gems/ruby-2.3.0)
=> (default)
   global
   rails5
   test

lalala12:~/workspace (master) $ rvm test
Unrecognized command line argument: 'test' ( see: 'rvm usage' )
lalala12:~/workspace (master) $ ruby --version
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
lalala12:~/workspace (master) $ rvm 2.3.0@test
lalala12:~/workspace (master) $ ruby --version
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
lalala12:~/workspace (master) $ rvm gemset list

gemsets for ruby-2.3.0 (found in /usr/local/rvm/gems/ruby-2.3.0)
   (default)
   global
   rails5
=> test

```

create的同时也switch到了那个gemset

```
lalala12:~/workspace (master) $ rvm gemset list

gemsets for ruby-2.3.0 (found in /usr/local/rvm/gems/ruby-2.3.0)
=> (default)
   global
   rails5
   test

lalala12:~/workspace (master) $ rvm 2.3.0@test --create
lalala12:~/workspace (master) $ rvm gemset list

gemsets for ruby-2.3.0 (found in /usr/local/rvm/gems/ruby-2.3.0)
   (default)
   global
   rails5
=> test

lalala12:~/workspace (master) $ gem list | grep pry
pry (0.10.3)
lalala12:~/workspace (master) $ 
```

.ruby-version .ruby-gemset 分别指定的是 Ruby 版本和 gemset 名字


http://cheat.errtheblog.com/s/rvm

List all rubies and gemsets
---------------------------

    rvm list         # List rubies only
    rvm list gemsets # List rubies and gemsets
    rvm gemset list  # List gemsets for current ruby



```
  
lalala12:~/workspace (master) $ rvm list gemsets

rvm gemsets

   ruby-1.9.3-p551 [ x86_64 ]
   ruby-1.9.3-p551@global [ x86_64 ]
   ruby-1.9.3-p551@rails3.2 [ x86_64 ]
   ruby-2.1.5 [ x86_64 ]
   ruby-2.1.5@global [ x86_64 ]
   ruby-2.1.5@rails4 [ x86_64 ]
   ruby-2.2.4 [ x86_64 ]
   ruby-2.2.4@global [ x86_64 ]
   ruby-2.2.4@rails4 [ x86_64 ]
   ruby-2.3.0 [ x86_64 ]
   ruby-2.3.0@global [ x86_64 ]
   ruby-2.3.0@rails5 [ x86_64 ]
=> ruby-2.3.0@test [ x86_64 ]

```

During installation of Ruby, RVM creates two gemsets:

- default - automatically selected when no @gemset specified: rvm use 1.9.3
- global  - super gemset, inherited by all other gemsets for the given ruby


https://ruby-china.org/topics/1057

```
我们团队完全依赖rvm 的gemset，
我们的项目使用统一的gemset命名，
比如rvm 1.9,3p0@awesome，
所以没有任何问题。
我不喜欢bundle exec rake，不如rake简单。
```  

http://stackoverflow.com/questions/21142065/create-ruby-version-and-ruby-gemset-with-rvm
https://gist.github.com/ery/ec6bdc8ee5775fe67207
生成.ruby-version and .ruby-gemset

```
lalala12:~/workspace (master) $ rvm --ruby-version use 2.3.0@test
Using /usr/local/rvm/gems/ruby-2.3.0 with gemset test
lalala12:~/workspace (master) $ ls -al
total 52
drwxr-xr-x  9 ubuntu ubuntu 4096 Mar  3 12:33 ./
drwxr-xr-x 21 ubuntu ubuntu 4096 Mar  3 11:46 ../
drwxr-xr-x  3 ubuntu ubuntu 4096 Mar  3 11:28 .c9/
drwxr-xr-x  8 ubuntu ubuntu 4096 Mar  3 11:28 .git/
-rw-r--r--  1 ubuntu ubuntu   13 Mar  3 11:28 .gitignore
-rw-rw-r--  1 ubuntu ubuntu    5 Mar  3 12:33 .ruby-gemset
-rw-rw-r--  1 ubuntu ubuntu   11 Mar  3 12:33 .ruby-version
-rwxr-xr-x  1 ubuntu ubuntu 1387 Mar  3 11:28 README.md*
drwxr-xr-x  4 ubuntu ubuntu 4096 Mar  3 11:28 html/
drwxr-xr-x  2 ubuntu ubuntu 4096 Mar  3 11:28 node.js/
drwxr-xr-x  2 ubuntu ubuntu 4096 Mar  3 11:28 php/
drwxr-xr-x  2 ubuntu ubuntu 4096 Mar  3 11:28 python/
drwxr-xr-x  2 ubuntu ubuntu 4096 Mar  3 11:28 ruby/
lalala12:~/workspace (master) $ cat .ruby-gemset
test
lalala12:~/workspace (master) $ cat .ruby-version
ruby-2.3.0
lalala12:~/workspace (master) $ 
```

效果是 一进去这个目录就会自动切换

```
lalala12:~ $ rvm gemset list

gemsets for ruby-2.3.0 (found in /usr/local/rvm/gems/ruby-2.3.0)
=> (default)
   global
   rails5
   test

lalala12:~ $ cd workspace/
lalala12:~/workspace (master) $ rvm gemset list

gemsets for ruby-2.3.0 (found in /usr/local/rvm/gems/ruby-2.3.0)
   (default)
   global
   rails5
=> test

lalala12:~/workspace (master) $ 
```


```
lalala12:~/workspace (master) $ rvm current
ruby-2.3.0@test
```

在其他 gemset中，不能使用default gemset 中的 gems
https://ruby-china.org/topics/12851

```
lalala12:~/workspace (master) $ rvm info | grep GEM_PATH
    GEM_PATH:     "/usr/local/rvm/gems/ruby-2.3.0@test:/usr/local/rvm/gems/ruby-2.3.0@global"
lalala12:~/workspace (master) $ ls -al /usr/local/rvm/gems/ruby-2.3.0@test
total 44
drwxrwsr-x 10 ubuntu rvm 4096 Mar  3 11:46 ./
drwxrwsr-x 13 root   rvm 4096 Mar  3 11:42 ../
drwxrwsr-x  2 ubuntu rvm 4096 Mar  3 11:46 bin/
drwxrwsr-x  2 ubuntu rvm 4096 Mar  3 11:46 build_info/
drwxrwsr-x  2 ubuntu rvm 4096 Mar  3 11:46 cache/
drwxrwsr-x  2 ubuntu rvm 4096 Mar  3 11:46 doc/
-rw-rw-r--  1 ubuntu rvm  459 Mar  3 11:42 environment
drwxrwsr-x  2 ubuntu rvm 4096 Mar  3 11:46 extensions/
drwxrwsr-x  6 ubuntu rvm 4096 Mar  3 11:46 gems/
drwxrwsr-x  2 ubuntu rvm 4096 Mar  3 11:46 specifications/
drwxrwsr-x  2 ubuntu rvm 4096 Mar  3 11:46 wrappers/
lalala12:~/workspace (master) $ ls -al /usr/local/rvm/gems/ruby-2.3.0@test/gems
total 24
drwxrwsr-x  6 ubuntu rvm 4096 Mar  3 11:46 ./
drwxrwsr-x 10 ubuntu rvm 4096 Mar  3 11:46 ../
drwxrwsr-x  5 ubuntu rvm 4096 Mar  3 11:46 coderay-1.1.1/
drwxrwsr-x  4 ubuntu rvm 4096 Mar  3 11:46 method_source-0.8.2/
drwxrwsr-x  4 ubuntu rvm 4096 Mar  3 11:46 pry-0.10.3/
drwxrwsr-x  4 ubuntu rvm 4096 Mar  3 11:46 slop-3.6.0/
lalala12:~/workspace (master) $ ls -al /usr/local/rvm/gems/ruby-2.3.0@global/gems
total 56
drwxrwsr-x 14 ubuntu rvm 4096 Jan 25 04:41 ./
drwxrwsr-x 10 ubuntu rvm 4096 Jan 25 04:41 ../
drwxrwsr-x  3 ubuntu rvm 4096 Dec 25 13:37 bundler-unload-1.0.2/
drwxrwsr-x  7 ubuntu rvm 4096 Dec 25 13:37 did_you_mean-1.0.0/
drwxrwsr-x  5 ubuntu rvm 4096 Dec 25 13:37 executable-hooks-1.3.2/
drwxrwsr-x  5 ubuntu rvm 4096 Dec 25 13:37 gem-wrappers-1.2.7/
drwxrwsr-x  4 ubuntu rvm 4096 Dec 25 13:37 minitest-5.8.3/
drwxrwsr-x  4 ubuntu rvm 4096 Dec 25 13:37 net-telnet-0.1.1/
drwxrwsr-x  4 ubuntu rvm 4096 Dec 25 13:37 power_assert-0.2.6/
drwxrwsr-x  7 ubuntu rvm 4096 Dec 25 13:37 rake-10.4.2/
drwxrwsr-x  3 ubuntu rvm 4096 Dec 25 13:37 rdoc-4.2.1/
drwxrwsr-x  4 ubuntu rvm 4096 Jan 25 04:41 rubygems-bundler-1.4.4/
drwxrwsr-x  3 ubuntu rvm 4096 Dec 25 13:37 rvm-1.11.3.9/
drwxrwsr-x  6 ubuntu rvm 4096 Dec 25 13:37 test-unit-3.1.5/
lalala12:~/workspace (master) $ 
```

gem which 命令很好用

```
lalala12:~/workspace (master) $ gem which rake
/usr/local/rvm/gems/ruby-2.3.0@global/gems/rake-10.4.2/lib/rake.rb
```

https://ruby-china.org/topics/7831
如果你要使用自己创建的 gemset，应该 $ rvm use 1.8.7@gemset_name；
如果这个 gemset 尚未创建，也可以直接 $ rvm use 1.8.7@gemset_name --create

default gemset下gem path是这样的

```
  GEM_PATH:     "/usr/local/rvm/gems/ruby-2.3.0:/usr/local/rvm/gems/ruby-2.3.0@global"
```

https://www.moncefbelyamani.com/enhance-your-ruby-development-with-rvm-gemsets-and-rvmrc/