Properly installing Ruby and Rubygems on Ubuntu - ruby

It seems this process is far harder than it should be.
Currently, I have ruby 1.9.2 installed manually. I wanted to update this to use RVM. So I installed that successfully, and then installed 1.9.3-p0, which is in my RVM directory under /zenph/.rvm
I upgraded rubygems using http://docs.rubygems.org/read/chapter/3
And my environment shows:
rvm 1.10.0
ruby 1.9.3p0
gem 1.8.12
So, why does "gem environment" show:
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.12
- RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [i686-linux]
- INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: /usr/bin/ruby1.9.1
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /usr/lib/ruby/gems/1.9.1
- /home/zenph/.gem/ruby/1.9.1
What can I try to resolve this?

To see which Ruby is the default one, open a terminal and use:
rvm list default
To specify a Ruby to be the default , open a terminal and use:
rvm --default use 1.9.3
Docs

Related

Find where a specific Ruby version is installed

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.

Removed rvm but gem env still says my INSTALLATION DIRECTORY is .rvm/gems which doesn't exist

I am trying to remove RVM from my desktop (which used ruby 1.9), so I can use vanilla ruby 2.3, which works on my formatted laptop. So I did
rvm implode
That got rid of the ~/.rvm dir and I soon got ruby --version to say it uses 2.3.1 etc. However when I do gem env, I still get:
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.8
- RUBY VERSION: 1.9.3 (2015-06-17 patchlevel 551) [java]
- INSTALLATION DIRECTORY: /home/foo/.rvm/gems/ruby-1.9.3-p551
- RUBY EXECUTABLE: /usr/share/jruby/bin/jruby
- EXECUTABLE DIRECTORY: /home/foo/.rvm/gems/ruby-1.9.3-p551/bin
- SPEC CACHE DIRECTORY: /home/foo/.gem/specs
Note that the /home/foo/.gem/ directory doesn't exist any more! How can I fix gem env? I am using Fedora 23 (soon 24) and I want to reset it to the system's default.
I tried a bunch of things (like reinstalling rubygems) with no luck.

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.

Bundle Install Fails

I am getting an error while running bundle install in my rails project.
sahil#debian:~/workspace/blog$ bundle install
/usr/bin/env: ruby: No such file or directory
Ruby
sahil#debian:~/workspace/blog$ ruby -v
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86__64-linux]
sahil#debian:~/workspace/blog$ which ruby
/home/sahil/.rvm/bin/ruby
Received the below error while installing ruby through rvm.
Error running 'env GEM_PATH=/home/sahil/.rvm/gems/ruby-2.0.0-p0:/home/sahil/.rvm/gems/ruby-2.0.0-p0#global:/home/sahil/.rvm/gems/ruby-2.0.0-p0:/home/sahil/.rvm/gems/ruby-2.0.0-p0#global GEM_HOME=/home/sahil/.rvm/gems/ruby-2.0.0-p0 /home/sahil/.rvm/rubies/ruby-2.0.0-p0/bin/ruby -d /home/sahil/.rvm/src/rubygems-2.0.3/setup.rb --verbose',
please read /home/sahil/.rvm/log/ruby-2.0.0-p0/rubygems.install.log
rvm env
sahil#debian:~$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.3
- RUBY VERSION: 2.0.0 (2013-02-24 patchlevel 0) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/sahil/.rvm/gems/ruby-2.0.0-p0
- RUBY EXECUTABLE: /home/sahil/.rvm/rubies/ruby-2.0.0-p0/bin/ruby
- EXECUTABLE DIRECTORY: /home/sahil/.rvm/gems/ruby-2.0.0-p0/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/sahil/.rvm/gems/ruby-2.0.0-p0
- /home/sahil/.rvm/gems/ruby-2.0.0-p0#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => t
rvm env looks ok. Not sure what have I missed.
please follow this basics steps for using RVM (copied from https://stackoverflow.com/a/15570121/497756):
rvm install 2.0.0
rvm use 2.0.0 --default # The default arg is needed only first time
gem install bundler
bundle install
also another answer showing more details: https://stackoverflow.com/a/10591301/497756

Failed WATIR installation Server 2003

I had to rebuild my box and I currently am unable to install Watir.
gem install watir
ERROR: Error installing watir:
activesupport requires Ruby version >= 1.8.7.
Which would be fine if Watir was able to use Ruby 1.8.7 . I am using
ruby -v
ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
gem -v
1.3.7
I am not sure when this started to occur, but the documentation on the site is lacking.
On Windows XP (Professional, Version 2002, Service Pack 3, fully pathched) I have installed ruby186-26.exe from RubyForge, as suggested at watir.com/installation.
C:\>ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
C:\>gem env
RubyGems Environment:
- VERSION: 0.9.4 (0.9.4)
- INSTALLATION DIRECTORY: c:/ruby/lib/ruby/gems/1.8
- GEM PATH:
- c:/ruby/lib/ruby/gems/1.8
- REMOTE SOURCES:
- http://gems.rubyforge.org
Automatic RubyGems update did not work:
C:\>gem update --system
Updating RubyGems...
ERROR: While executing gem ... (Gem::RemoteSourceException)
HTTP Response 302
I have downloaded rubygems-update-1.3.7.gem from RubyForge, copied it to the folder where I have command prompt open (C:\ in this example) and installed:
C:\>gem install rubygems-update-1.3.7.gem
Successfully installed rubygems-update, version 1.3.7
Installing ri documentation for rubygems-update-1.3.7...
Installing RDoc documentation for rubygems-update-1.3.7...
Could not find main page README
Could not find main page README
Could not find main page README
Could not find main page README
C:\>update_rubygems
RubyGems 1.3.7 installed
...
To make sure I have the latest RubyGems:
C:\>gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
- INSTALLATION DIRECTORY: c:/ruby/lib/ruby/gems/1.8
- RUBY EXECUTABLE: c:/ruby/bin/ruby.exe
- EXECUTABLE DIRECTORY: c:/ruby/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mswin32-60
- GEM PATHS:
- c:/ruby/lib/ruby/gems/1.8
- C:/Documents and Settings/Administrator/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
Now Watir did not want to install:
C:\>gem install watir
ERROR: Error installing watir:
activesupport requires Ruby version >= 1.8.7.
I have installed activesupport-2.3.8 as suggested by Charley Baker, and I was able to install Watir:
C:\>gem install activesupport --version="2.3.8"
Successfully installed activesupport-2.3.8
1 gem installed
Installing ri documentation for activesupport-2.3.8...
Installing RDoc documentation for activesupport-2.3.8...
C:\>gem install watir
Successfully installed firewatir-1.6.5
Successfully installed nokogiri-1.4.3.1-x86-mswin32
Successfully installed watir-1.6.5
3 gems installed
...
I had a similar issue just now and thought I would add a comment to this issue. Our dev vm's are currently running windows 7, therefore I needed to run my command prompt as administrator for the gem installation to work correctly.

Resources