Find where a specific Ruby version is installed - ruby

On Mac, I used to have rbenv as Ruby version manager but recently switched to asdf. I want to create a Ruby on Rails 7.0.4 but it uses an outdated version and I'd like to locate it.
$ rails new app
"Rails 7 requires Ruby 2.7.0 or newer.
You're running
ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin"
$ which ruby
/Users/kawsay/.asdf/shims/ruby
$ ruby -v
ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c5) [arm64-darwin21]
$ irb
irb(main):001:0> RUBY_VERSION
=> "3.0.5"
$ asdf list ruby
2.7.4
*3.0.5
$ brew info ruby
==> ruby: stable 3.2.0 (bottled), HEAD [keg-only]
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 3.2.33
- RUBY VERSION: 3.0.5 (2022-11-24 patchlevel 211) [arm64-darwin21]
- INSTALLATION DIRECTORY: /Users/kawsay/.gem
- USER INSTALLATION DIRECTORY: /Users/kawsay/.gem/ruby/3.0.0
- RUBY EXECUTABLE: /Users/kawsay/.asdf/installs/ruby/3.0.5/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /Users/kawsay/.gem/bin
- SPEC CACHE DIRECTORY: /Users/kawsay/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/kawsay/.asdf/installs/ruby/3.0.5/etc
- RUBYGEMS PLATFORMS:
- ruby
- arm64-darwin-21
- GEM PATHS:
- /Users/kawsay/.gem
- /Users/kawsay/.gem/ruby/3.0.0
- /Users/kawsay/.asdf/installs/ruby/3.0.5/lib/ruby/gems/3.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/kawsay/.asdf/installs/ruby/3.0.5/bin
- /Users/kawsay/.asdf/shims
- /opt/homebrew/opt/asdf/libexec/bin
- /Users/kawsay/.cargo/bin
- /opt/homebrew/opt/openssl#2.8/bin
- /opt/homebrew/opt/python#3.8/bin/python3
- /opt/homebrew/bin
- /opt/homebrew/sbin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
$ which rbenv
rbenv not found
$ which rvm
rbenv not found
How can I find where ruby 2.6.8p205 is installed ?

You have an issue where you have system Ruby, brew Ruby, asdf Ruby, and rbenv Ruby. In short, your system is confused about where to find things.
The first step is to remove brew's Ruby installation:
brew uninstall ruby
The second step is to remove rbenv completely. (or use the official docs)
The third step is to make sure that system Ruby does not have the Rails gem installed. Start a shell without loading your profile so that you can bypass asdf and any other configuration:
env -i bash --norc --noprofile
Then confirm it's pointing at system Ruby: (your version will differ slightly depending on your version of macOS)
$ ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin22]
Then uninstall the Rails gem:
gem uninstall rails
But while you're at it you might want to remove all the gems you installed using system Ruby: (ignore any errors here)
gem uninstall -aIx
Now close that shell session and switch back to your default shell. Make sure that your shell profile is cleared of anything related to rbenv and that you have no GEM_* environment variables being set. (assuming you use ZSH, check every ~/.zsh* file and ~/.gemrc) Then start a new shell session to load the cleaned profiles.
Then make sure asdf has a properly groomed environment:
asdf reshim
Now when you run gem env you should see output like this:
RubyGems Environment:
- RUBYGEMS VERSION: 3.4.1
- RUBY VERSION: 3.2.0 (2022-12-25 patchlevel 0) [arm64-darwin22]
- INSTALLATION DIRECTORY: /Users/foo/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0
- USER INSTALLATION DIRECTORY: /Users/foo/.gem/ruby/3.2.0
- RUBY EXECUTABLE: /Users/foo/.asdf/installs/ruby/3.2.0/bin/ruby
- GIT EXECUTABLE: /opt/homebrew/bin/git
- EXECUTABLE DIRECTORY: /Users/foo/.asdf/installs/ruby/3.2.0/bin
- SPEC CACHE DIRECTORY: /Users/foo/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/foo/.asdf/installs/ruby/3.2.0/etc
- RUBYGEMS PLATFORMS:
- ruby
- arm64-darwin-22
- GEM PATHS:
- /Users/foo/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0
- /Users/foo/.gem/ruby/3.2.0
Note the difference between INSTALLATION DIRECTORY and EXECUTABLE DIRECTORY in this output and yours. You need to have output that looks like this, otherwise that means that asdf is not installed properly and you should restart the installation of asdf from the beginning.
Afterwards, re-run gem install rails and you should be able to complete rails new app successfully.
If not, there is a shortcut to run commands with asdf for any given command:
asdf exec gem install rails
asdf exec rails new app
asdf exec rails server
This should bypass everything else and use asdf exclusively.

Related

Weird issue with ruby version on mac

I am trying to create a rails app and fails like so:
$ rails new blog
Rails 6 requires Ruby 2.5.0 or newer.
You're running:
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
Please upgrade to Ruby 2.5.0 or newer to continue.
However, my ruby version is 2.6.3 according to my system:
$ ruby --version
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]
$ which ruby
/Users/flaab/.rbenv/shims/ruby
Rbenv has 2.6.5 activated.
$ rbenv versions
system
* 2.6.5 (set by /Users/flaab/.ruby-version)
mruby-dev
But it recognizes the wrong one as well.
$ which -a ruby
/Users/flaab/.rbenv/shims/ruby
/usr/bin/ruby
My gem env is...
flaab#MBP-de-Arturo ~ $ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 3.0.3
- RUBY VERSION: 2.6.5 (2019-10-01 patchlevel 114) [x86_64-darwin18]
- INSTALLATION DIRECTORY: /Users/flaab/.gem
- USER INSTALLATION DIRECTORY: /Users/flaab/.gem/ruby/2.6.0
- RUBY EXECUTABLE: /Users/flaab/.rbenv/versions/2.6.5/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /Users/flaab/.gem/bin
- SPEC CACHE DIRECTORY: /Users/flaab/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/flaab/.rbenv/versions/2.6.5/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-18
- GEM PATHS:
- /Users/flaab/.gem
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- "echo \"gem" => "--no-document\" > ~/.gemrc"
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/flaab/.rbenv/versions/2.6.5/bin
- /opt/local/libexec/rbenv
- /Users/flaab/.rbenv/shims
- /usr/local/bin
- /opt/local/bin
- /opt/local/sbin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /Users/flaab/bin
- /Users/flaab/.rbenv/shims
- /sw/bin
- /Users/flaab/.local/lib/npm/bin
- /Users/flaab/.composer/vendor/bin
How can I instruct gem to use the 2.6.5 version of ruby mentioned above?
Thanks in advance
To no avail. Ditched mac and went back to developing on debian. No issues.
Either run rbenv global 2.5.0 to set your global ruby or create a .ruby-version file in the app directory to instruct rbenv to use a specific version.
echo "2.5.0" >> .ruby-version and then try again.
Documentation
Do you have this already added to your .bash_profile ?
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
If not add the above lines to the bottom of the file, then close and restart your terminal(s).
It looks like your EXECUTABLE DIRECTORY may not be set correctly. Try the following command:
rbenv shell 2.6.5
Also, make sure you're in a new empty directory and do
rbenv local 2.6.5
Then try rails command again
rails new blog

Jekyll: command not found problem despite installated with most recent versions

I am having trouble with the Jekyll installation. Everything is up to date with Ruby, Homebrew and Gems:
Quocs-MacBook-Air:~ quochoantrinh$ brew -v
Homebrew 2.1.6
Homebrew/homebrew-core (git revision 2796; last commit 2019-07-01)
Quocs-MacBook-Air:~ quochoantrinh$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin16]
Quocs-MacBook-Air:~ quochoantrinh$ gem -v
3.0.3
Then I ran the following from the Jekyll on macOS setup from the official website (https://jekyllrb.com/docs/installation/macos/)
export PATH=/usr/local/opt/ruby/bin:$PATH
Afterwards I did the next commands:
gem install --user-install bundler jekyll
export PATH=$HOME/.gem/ruby/2.6.3/bin:$PATH
However when I run jekyll in my terminal it gives me the "command not found".
This is my gem env
Quocs-MacBook-Air:~ quochoantrinh$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 3.0.3
- RUBY VERSION: 2.6.3 (2019-04-16 patchlevel 62) [x86_64-darwin16]
- INSTALLATION DIRECTORY: /Users/quochoantrinh/.rvm/gems/ruby-2.6.3
- USER INSTALLATION DIRECTORY: /Users/quochoantrinh/.gem/ruby/2.6.0
- RUBY EXECUTABLE: /usr/local/opt/ruby/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /Users/quochoantrinh/.rvm/gems/ruby-2.6.3/bin
- SPEC CACHE DIRECTORY: /Users/quochoantrinh/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /usr/local/Cellar/ruby/2.6.3/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-16
- GEM PATHS:
- /Users/quochoantrinh/.rvm/gems/ruby-2.6.3
- /Users/quochoantrinh/.rvm/rubies/ruby-2.6.3/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/opt/ruby/bin
- /Users/quochoantrinh/.yarn/bin
- /Users/quochoantrinh/.config/yarn/global/node_modules/.bin
- /Users/quochoantrinh/anaconda3/bin
- /Users/quochoantrinh/anaconda3/bin
- /Users/quochoantrinh/anaconda/bin
- /Users/quochoantrinh/.gem/ruby/2.6.3/bin
- /Users/quochoantrinh/.rvm/gems/ruby-2.6.3/bin
- /Users/quochoantrinh/.rvm/gems/ruby-2.6.3#global/bin
- /Users/quochoantrinh/.rvm/rubies/ruby-2.6.3/bin
- /Users/quochoantrinh/.yarn/bin
- /Users/quochoantrinh/.config/yarn/global/node_modules/.bin
- /Users/quochoantrinh/anaconda3/bin
- /Users/quochoantrinh/anaconda3/bin
- /Users/quochoantrinh/anaconda/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /Library/Frameworks/Mono.framework/Versions/Current/Commands
- /Users/quochoantrinh/.rvm/bin
There are a few things going on here, but to fix your immediate problem, I believe this should do it:
export PATH="$HOME/.gem/ruby/2.6.0/bin:$PATH"
When you use the --user-install flag, it installs gems in the USER_INSTALLATION_DIRECTORY that's mentioned when you run gem env, which in your case is /Users/quochoantrinh/.gem/ruby/2.6.0, and then you have to add /bin when you add it to the PATH. It's not so much that you want to change the USER_INSTALLATION_DIRECTORY, but that you need to set the PATH to point to the USER_INSTALLATION_DIRECTORY. I know it's not very intuitive because you would think that you want to use the path that corresponds to your current Ruby version (2.6.3), but the USER_INSTALLATION_DIRECTORY always ends with a 0. It only uses the first 2 digits of the Ruby version. If you ever upgrade to 2.7.2, which is the latest version as of today, your PATH has to point to 2.7.0.
Note that running the export PATH command above will only work during your current session. If you want to be able to use jekyll every time you quit and relaunch Terminal, or open a new tab, you need to add that export PATH command to your shell startup file, typically either ~/.bash_profile or ~/.zshrc. If you're not sure which shell you are using, read this: https://www.moncefbelyamani.com/which-shell-am-i-using-how-can-i-switch/
I also noticed that you seem to have installed Ruby with both Homebrew and RVM. This could potentially cause problems. I always recommend that people install Ruby with a Ruby manager (such as RVM, rbenv, and chruby), because most of them automatically set everything up for you. You don't have to worry about setting the PATH manually and thinking about whether to add --user-install. My preferred manager is chruby because it's the lightest and easiest to use.
Based on your gem env, it looks like you are currently using the Homebrew version of Ruby, so I wanted to let you know of another issue you might run into. (I can tell it's Homebrew by looking at the RUBY_EXECUTABLE, and I know from experience that Homebrew installs things in /usr/local and I recognize that path as the Homebrew Ruby.)
Let's say you want to install rails months from now, and you type gem install rails (without the --user-install flag). Once it's installed, if you try to use the rails command, you will get "command not found", because when you use the Homebrew version of Ruby, and you don't use --user-install, the gem will get installed in a directory managed by Homebrew, not in your USER_INSTALLATION_DIRECTORY. The Jekyll documentation forgot to point out that you need to add the Homebrew gems location to your PATH. The fix is covered in my definitive guide to installing Ruby gems on a Mac, and also in the pull request I opened to fix the Jekyll documentation.
To understand more about how PATH works, and why you can get a "command not found" error, I recommend this article:
https://www.moncefbelyamani.com/troubleshooting-command-not-found-in-the-terminal/

Can't seem to run ruby 2.6.0 homebrew version - always references back to system ruby 2.3.0

This is the situation: I am running mac OS Mojave 10.14.3 - It seems system is running ruby v2.3.0 and installed homebrew ruby 2.6.x when I try to run sass I get the following error:
> Sass is watching for changes. Press Ctrl-C to stop.
Gem::MissingSpecError: Could not find 'ffi' (>= 0.5.0, < 2) among 20 total gem(s)
Checked in 'GEM_PATH=/Users/samuellarcher/.gem/ruby/2.3.0:/Library/Ruby/Gems/2.3.0:/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/gems/2.3.0', execute `gem env` for more information
Running gem env returns:
> RubyGems Environment:
- RUBYGEMS VERSION: 3.0.3
- RUBY VERSION: 2.6.2 (2019-03-13 patchlevel 47) [x86_64-darwin18]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.6.0
- USER INSTALLATION DIRECTORY: /Users/samuellarcher/.gem/ruby/2.6.0
- RUBY EXECUTABLE: /usr/local/opt/ruby/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /usr/local/lib/ruby/gems/2.6.0/bin
- SPEC CACHE DIRECTORY: /Users/samuellarcher/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /usr/local/Cellar/ruby/2.6.2/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-18
- GEM PATHS:
- /usr/local/lib/ruby/gems/2.6.0
- /Users/samuellarcher/.gem/ruby/2.6.0
- /usr/local/Cellar/ruby/2.6.2/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/opt/ruby/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
Now, when i do a:
whereis ruby
it returns:
/usr/bin/ruby
and
echo $PATH
returns
/usr/local/opt/ruby/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
on top of that, the path priority under /private/etc/paths is set to:
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
which seems correct to me. The .bash_profile file contains:
export PATH="/usr/local/opt/ruby/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
Checking gem directories:
ls /usr/local/lib/ruby/gems/2.6.0/gems/
returns
ffi-1.10.0 rb-fsevent-0.10.3 rb-inotify-0.10.0 sass-3.7.3 sass-listen-4.0.0 test-unit-3.3.0
with the missing ffi gem we are after.
ls .gem/ruby/2.3.0/cache/
returns
CFPropertyList-3.0.0.gem faraday-cookie_jar-0.0.6.gem mini_magick-4.5.1.gem simctl-1.6.5.gem
addressable-2.6.0.gem faraday_middleware-0.13.1.gem multi_json-1.13.1.gem slack-notifier-2.3.2.gem
atomos-0.1.3.gem fastimage-2.1.5.gem multi_xml-0.6.0.gem terminal-notifier-1.8.0.gem
babosa-1.0.2.gem fastlane-2.117.1.gem multipart-post-2.0.0.gem terminal-table-1.8.0.gem
bundler-2.0.1.gem gh_inspector-1.1.3.gem nanaimo-0.2.6.gem tty-cursor-0.6.1.gem
claide-1.0.2.gem google-api-client-0.23.9.gem naturally-2.2.0.gem tty-screen-0.6.5.gem
colored-1.2.gem google-cloud-core-1.3.0.gem os-1.0.0.gem tty-spinner-0.9.0.gem
colored2-3.1.2.gem google-cloud-env-1.0.5.gem plist-3.5.0.gem uber-0.1.0.gem
commander-fastlane-4.4.6.gem google-cloud-storage-1.16.0.gem public_suffix-2.0.5.gem unf-0.1.4.gem
declarative-0.0.10.gem googleauth-0.6.7.gem representable-3.0.4.gem unf_ext-0.0.7.5.gem
declarative-option-0.1.0.gem highline-1.7.10.gem retriable-3.1.2.gem unicode-display_width-1.5.0.gem
digest-crc-0.4.1.gem http-cookie-1.0.3.gem rouge-2.0.7.gem word_wrap-1.0.0.gem
domain_name-0.5.20180417.gem httpclient-2.8.3.gem rubygems-update-3.0.2.gem xcode-install-2.3.0.gem
dotenv-2.7.1.gem jwt-2.1.0.gem rubygems-update-3.0.3.gem xcodeproj-1.8.1.gem
emoji_regex-1.0.1.gem memoist-0.16.0.gem rubyzip-1.2.2.gem xcpretty-0.3.0.gem
excon-0.62.0.gem mime-types-3.2.2.gem security-0.1.3.gem xcpretty-travis-formatter-1.0.0.gem
faraday-0.15.4.gem mime-types-data-3.2018.0812.gem signet-0.11.0.gem
without the missing ffi gem
I might miss something fundemental but ideally I would like the homebrew ruby version 2.6.x running when I run sass - so where from here?
As per M. Zinovski's suggestion I uninstalled homebrew ruby and installed rbenv via homebrew. I followed instructions added
eval "$(rbenv init -)"
to .bash_profile - check installation seems fine.
SamuelserBook15:~ samuellarcher$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
Checking for `rbenv' in PATH: /usr/local/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20190314)
Counting installed Ruby versions: 2 versions
Checking RubyGems settings: OK
Auditing installed plugins: OK
Local and global version set to newly installed rbenv 2.6.2
samuellarcher$ rbenv version
2.6.2 (set by /Users/samuellarcher/.ruby-version)
samuellarcher$ ruby -v
ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-darwin18]
However - when I ran sass - same old error - still referencing to 2.3.0 and ffi gem missing. So... absolutely min-bobbeling .. 2.6.2 is running why is it still pointing to 2.3.0 gem files???

Managing Path With rbenv

I installed rbenv to manage my ruby installations, and then I subsequently ran gem install github-pages to get jekyll and other dependencies needed for developing a github pages site. However, now when I try to run the jekyll command I get
The program 'jekyll' is currently not installed. You can install it by typing:
sudo apt-get install jekyll
I assume this is a path issue, but I thought the path was supposed to be handled by rbenv. I also previously had the same issue when completing the same process using RVM instead of rbenv. How can I fix this?
I just tried running gem env and got the following:
RubyGems Environment:
- RUBYGEMS VERSION: 2.5.1
- RUBY VERSION: 2.3.0 (2015-12-25 patchlevel 0) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/daniel/.rvm/gems/ruby-2.3.0
- USER INSTALLATION DIRECTORY: /home/daniel/.gem/ruby/2.3.0
- RUBY EXECUTABLE: /home/daniel/.rbenv/versions/2.3.0/bin/ruby
- EXECUTABLE DIRECTORY: /home/daniel/.rvm/gems/ruby-2.3.0/bin
- SPEC CACHE DIRECTORY: /home/daniel/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /home/daniel/.rbenv/versions/2.3.0/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/daniel/.rvm/gems/ruby-2.3.0
- /home/daniel/.rvm/gems/ruby-2.3.0#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- "gem" => "--no-document"
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /home/daniel/.rbenv/versions/2.3.0/bin
- /home/daniel/.rbenv/libexec
- /home/daniel/.rbenv/plugins/ruby-build/bin
- /home/daniel/.rbenv/plugins/ruby-build/bin
- /home/daniel/.rbenv/shims
- /home/daniel/.rbenv/bin
- /opt/jdk1.8.0_65/bin/home/daniel/.rvm/gems/ruby-2.3.0/bin
- /home/daniel/.rvm/gems/ruby-2.3.0#global/bin
- /home/daniel/.rvm/rubies/ruby-2.3.0/bin
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
- /usr/games
- /usr/local/games
- /home/daniel/.rvm/bin
You have both rbenv and RVM installed and running at the same time. Don't do that.
Per the rbenv documentation:
Compatibility note: rbenv is incompatible with RVM. Please make sure to fully uninstall RVM and remove any references to it from your shell initialization files before installing rbenv.
The why to that delves into how the shell finds commands which would be off-topic. You can research that if you're so inclined.
Should I just copy /home/daniel/.rmv/gems to /home/daniel/.rbenv/bin?
No.
"just copy" would run the risk of havoc breaking loose farther down the road.
I'd recommend temporarily disabling rbenv by commenting-out its initialization in your ~/.bash_profile, then restart your terminal session resulting in only RVM being available. Then run
gem list --no-versions > ~/rvm-gems-list
Then reenable rbenv by removing the comment mark, and comment-out the RVM initialization and restart your terminal session to give rbenv control. Run
xargs gem install --conservative < ~/rvm-gems-list
which will spin through all the gems installed in your RVM instance and let gem install any that are missing. Once that finishes you can delete the rvm-gems-list file:
rm ~/rvm-gems-list
At this point you need to remove RVM, or toggle back and forth between rbenv and RVM by alternately enabling/disabling them as you did above. You can't have them both running at the same time, and trying to remember where gems are installed will be a pain so I'd suggest sticking with one or the other.
(I use them both, only on separate systems.)

Multi-User RVM - gem path different when using sudo to execute Ruby script

I have installed RVM in a Multi-User configuration. Everything seems to work, but the gem installation folder and path are different when I have to use sudo to execute a Ruby script. This ends up resulting in gems not being available to a script.
If I execute gem env I get the following:
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.8
- RUBY VERSION: 2.2.2 (2015-04-13 patchlevel 95) [x86_64-darwin14]
- INSTALLATION DIRECTORY: /usr/local/rvm/gems/ruby-2.2.2
- RUBY EXECUTABLE: /usr/local/rvm/rubies/ruby-2.2.2/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/rvm/gems/ruby-2.2.2/bin
- SPEC CACHE DIRECTORY: /Users/patrickaikens/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-14
- GEM PATHS:
- /usr/local/rvm/gems/ruby-2.2.2
- /usr/local/rvm/gems/ruby-2.2.2#global
...
If I execute sudo gem env, I get this instead:
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.8
- RUBY VERSION: 2.2.2 (2015-04-13 patchlevel 95) [x86_64-darwin14]
- INSTALLATION DIRECTORY: /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0
- RUBY EXECUTABLE: /usr/local/rvm/rubies/ruby-2.2.2/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/rvm/rubies/ruby-2.2.2/bin
- SPEC CACHE DIRECTORY: /Users/patrickaikens/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-14
- GEM PATHS:
- /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0
- /Users/patrickaikens/.gem/ruby/2.2.0
...
Notice that INSTALLATION_DIRECTORY and GEM PATHS are different, but both outputs indicate that RVM is "active". I don't have a .rvm folder in either my own home directory or in root's home directory. Why is RVM handling those paths differently, and can I make then the same? Using rvmsudo does seem to work, but I really don't want to have to remember which of my admin scripts will run Ruby at some point if I don't have to.
The reason you see different information appearing when running normally and when running as "sudo" is because using sudo invokes the system ruby, bypassing RVM, rather than the version selected in your RVM.
I'm having this issue myself.
The RVM troubleshooting page suggests using rvmsudo instead, but then also suggests you wont need to.

Resources