Reputation: 7986
First I installed fluentd with Ruby 2.6.3.
$ rbenv versions
* system (set by /Users/jing/.rbenv/version)
2.7.5
$ gem
gem env
RubyGems Environment:
- RUBYGEMS VERSION: 3.0.3
- RUBY VERSION: 2.6.3 (2019-04-16 patchlevel 62) [universal.x86_64-darwin19]
- INSTALLATION DIRECTORY: /Users/jing/.gem
- USER INSTALLATION DIRECTORY: /Users/jing/.gem/ruby/2.6.0
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /Users/jing/.gem/bin
- SPEC CACHE DIRECTORY: /Users/jing/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-19
- GEM PATHS:
- /Users/jing/.gem
- /Users/jing/.gem/ruby/2.6.0
- /Library/Ruby/Gems/2.6.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /usr/local/Cellar/rbenv/1.2.0/libexec
- /Users/jing/.rbenv/shims
- /Users/jing/.tiup/bin
- /Users/jing/opt/anaconda3/condabin
- /usr/local/sbin
- /Users/jing/code/github/zk-code/scripts
- /Users/jing/tools/apache-zookeeper-3.5.5-bin/bin
- /Users/jing/code/github/trace/sky/skywalking-cli/bin
- /Users/jing/tools/apache-skywalking-apm-bin-es7/bin
- /usr/local/opt/ruby/bin
- /Users/jing/tools/apache-maven-3.6.3/bin
- /Users/jing/.gem/bin
- /Users/jing/.cargo/bin
- /Users/jing/code/github/rtc/depot_tools
- /Users/jing/.gem/ruby/2.3.0/bin
- /usr/local/opt/coreutils/libexec/gnubin
- /Users/jing/tools/apache-skywalking-apm-bin-es7/bin
- /Users/jing/tools/confluent-6.1.0/bin
- /usr/local/opt/findutils/libexec/gnubin
- /usr/local/opt/gnu-sed/libexec/gnubin
- /Users/jing/tools/mongodb-osx-x86_64-4.0.2/bin
- /usr/local/opt/[email protected]/bin
- /Users/jing/tools/spark-2.2.0-bin-hadoop2.7/bin
- /Users/jing/bin
- /usr/local/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /Library/TeX/texbin
- /Library/Apple/usr/bin
- /Applications/Wireshark.app/Contents/MacOS
- /Users/jing/go/bin
- /Users/jing/.pub-cache/bin
- /Applications/Visual Studio Code.app/Contents/Resources/app/bin
- /usr/local/opt/fzf/bin
$ gem install fluentd
Successfully installed fluentd-1.14.3
Parsing documentation for fluentd-1.14.3
Done installing documentation for fluentd after 3 seconds
1 gem installed
$ ls ~/.gem/gems -lrt | tail -n1
drwxr-xr-x 28 jing staff 896 Dec 7 10:33 fluentd-1.14.3
$ head -n1 ~/.gem/bin/fluentd
#!/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
Then I chose Ruby 2.7.5 with rbenv and installed fluentd again.
$ rbenv shell 2.7.5
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 3.1.6
- RUBY VERSION: 2.7.5 (2021-11-24 patchlevel 203) [x86_64-darwin19]
- INSTALLATION DIRECTORY: /Users/jing/.gem
- USER INSTALLATION DIRECTORY: /Users/jing/.gem/ruby/2.7.0
- RUBY EXECUTABLE: /Users/jing/.rbenv/versions/2.7.5/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /Users/jing/.gem/bin
- SPEC CACHE DIRECTORY: /Users/jing/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/jing/.rbenv/versions/2.7.5/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-19
- GEM PATHS:
- /Users/jing/.gem
- /Users/jing/.gem/ruby/2.7.0
- /Users/jing/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/jing/.rbenv/versions/2.7.5/bin
- /usr/local/Cellar/rbenv/1.2.0/libexec
- /Users/jing/.rbenv/shims
- /Users/jing/.tiup/bin
- /Users/jing/opt/anaconda3/condabin
- /usr/local/sbin
- /Users/jing/code/github/zk-code/scripts
- /Users/jing/tools/apache-zookeeper-3.5.5-bin/bin
- /Users/jing/code/github/trace/sky/skywalking-cli/bin
- /Users/jing/tools/apache-skywalking-apm-bin-es7/bin
- /usr/local/opt/ruby/bin
- /Users/jing/tools/apache-maven-3.6.3/bin
- /Users/jing/.gem/bin
- /Users/jing/.cargo/bin
- /Users/jing/code/github/rtc/depot_tools
- /Users/jing/.gem/ruby/2.3.0/bin
- /usr/local/opt/coreutils/libexec/gnubin
- /Users/jing/tools/apache-skywalking-apm-bin-es7/bin
- /Users/jing/tools/confluent-6.1.0/bin
- /usr/local/opt/findutils/libexec/gnubin
- /usr/local/opt/gnu-sed/libexec/gnubin
- /Users/jing/tools/mongodb-osx-x86_64-4.0.2/bin
- /usr/local/opt/[email protected]/bin
- /Users/jing/tools/spark-2.2.0-bin-hadoop2.7/bin
- /Users/jing/bin
- /usr/local/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /Library/TeX/texbin
- /Library/Apple/usr/bin
- /Applications/Wireshark.app/Contents/MacOS
- /Users/jing/go/bin
- /Users/jing/.pub-cache/bin
- /Applications/Visual Studio Code.app/Contents/Resources/app/bin
- /usr/local/opt/fzf/binio Code.app/Contents/Resources/app/bin
- /usr/local/opt/fzf/bin
$ gem install fluentd
Successfully installed fluentd-1.14.3
Parsing documentation for fluentd-1.14.3
Done installing documentation for fluentd after 3 seconds
1 gem installed
$ ls ~/.gem/gems -lrt | tail -n1
drwxr-xr-x 28 jing staff 896 Dec 7 10:37 fluentd-1.14.3
$ head -n1 ~/.gem/bin/fluentd
#!/Users/jing/.rbenv/versions/2.7.5/bin/ruby
From the above console session, I knew that fluent is re-installed at the same location.
I don't want to have gems from one Ruby version overwrite gems from the other ruby version. Is there a way to keep one gem for one Ruby version separately?
Upvotes: 1
Views: 588
Reputation: 9730
I personally created this shell function for this:
function switch-ruby-gems() {
rm -rf "${GEM_HOME}"
gem install bundler
bundle install
}
Upvotes: 0
Reputation: 1844
By design, you can't. The project considers this a feature:
One thing well. rbenv is concerned solely with switching Ruby versions.
Buuuuut, you can use a plugin to create Gemsets, which you can switch on a per-application basis.
I've not used it, but it appears the rbenv-gemset
plugin would give you what you're after: https://github.com/jf/rbenv-gemset.
Once installed, you can create a default gemset in your project's root directory:
$rbenv gemset init
Upvotes: 2