Trouble in understanding what Ruby version I am "actually"/"effectively" running - ruby

I am on Mac OS an I am running Snow Leopard Version 10.6.8. I am using RVM in order to manage my Ruby installations (and so to use the Ruby on Rails framework) but I am in trouble when I see some outputs in the log, mostly related to the current version in use when I get some warning/error message. That is, I previously run these commands in the terminal window:
$ which ruby
/<ABSOLUTE_PATH>/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
$ rvm install 1.9.3
Installing Ruby from source to: /<ABSOLUTE_PATH>/.rvm/rubies/ruby-1.9.3-p0, this may take a while depending on your cpu(s)...
ruby-1.9.3-p0 - #fetching
...
Fetching yaml-0.1.4.tar.gz to /<ABSOLUTE_PATH>/.rvm/archives
Extracting yaml-0.1.4.tar.gz to /<ABSOLUTE_PATH>/.rvm/src
Configuring yaml in /<ABSOLUTE_PATH>/.rvm/src/yaml-0.1.4.
Compiling yaml in /<ABSOLUTE_PATH>/.rvm/src/yaml-0.1.4.
Installing yaml to /<ABSOLUTE_PATH>/.rvm/usr
ruby-1.9.3-p0 - #configuring
ruby-1.9.3-p0 - #compiling
ruby-1.9.3-p0 - #installing
Removing old Rubygems files...
Installing rubygems-1.8.10 for ruby-1.9.3-p0 ...
Installation of rubygems completed successfully.
ruby-1.9.3-p0 - adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.3-p0 - #importing default gemsets (/<ABSOLUTE_PATH>/.rvm/gemsets/)
Install of ruby-1.9.3-p0 - #complete
$ which ruby
/<ABSOLUTE_PATH>/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
$ rvm use --default 1.9.3
Using /<ABSOLUTE_PATH>/.rvm/gems/ruby-1.9.3-p0
$ which ruby
/<ABSOLUTE_PATH>/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
Until here it seems to be OK.
However, when I get some error like in this question related to the DelayedJob gem, I see in the log that the system is using still Ruby 1.9.2-p290:
# Note the 'ruby-1.9.2-p290'
undefined method `send_register_email\' for #<Syck::DomainType:0x00000108e2f870>\n/<ABSOLUTE_PATH>/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/performable_mailer.rb:6:in
...
What is wrong? How can I solve the issue?

as #sarnold suggests you will have to restart any long running processes such as daemons.
Another thing is that if it is running in a cron tab, make sure the cron task is running as the right user. If you set up RVM for a user, and not the system, then root, or any other user than you didn't set up RVM for, will be using system ruby.
You carefully snipped out ""
Note this can easily happen with
sudo rake some:task # that has to do something as root like open a low port or move a file
this will run as root and not do the right RVM sourcing. To fix this, there is
rvmsudo rake some:task

Related

Ruby gem installed, but unable to require it

I've installed a number of gems, however when i go to 'require' them i get "no such file to load error":
~/Documents/Projects/Ruby Scripts/Domain » ./whois.rb
/System//Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in 'require': cannot load such file -- whois (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from ./whois.rb:3:in `<main>'
I have installed the gem and it appears to have installed sucessfully:
~ » gem install whois
Fetching: whois-4.0.1.gem (100%)
Successfully installed whois-4.0.1
Parsing documentation for whois-4.0.1
Installing ri documentation for whois-4.0.1
Done installing documentation for whois after 0 seconds
1 gem installed
Running gem list shows the gem installed as a local gem:
*** LOCAL GEMS ***
activesupport (5.1.0)
addressable (2.5.1)
...
whois (4.0.1)
Running gem env shows the gem path that i would expect as i am using rbenv:
RubyGems Environment:
- RUBYGEMS VERSION: 2.6.11
- RUBY VERSION: 2.4.1 (2017-03-22 patchlevel 111) [x86_64-darwin16]
- INSTALLATION DIRECTORY: /Users/perfektion/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0
- USER INSTALLATION DIRECTORY: /Users/perfektion/.gem/ruby/2.4.0
- RUBY EXECUTABLE: /Users/perfektion/.rbenv/versions/2.4.1/bin/ruby
- EXECUTABLE DIRECTORY: /Users/perfektion/.rbenv/versions/2.4.1/bin
- SPEC CACHE DIRECTORY: /Users/perfektion/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/perfektion/.rbenv/versions/2.4.1/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-16
- GEM PATHS:
- /Users/perfektion/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0
- /Users/perfektion/.gem/ruby/2.4.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/perfektion/.rbenv/versions/2.4.1/bin
- /usr/local/Cellar/rbenv/1.1.0/libexec
- /Users/perfektion/.rbenv/shims
- /Users/perfektion/.rbenv/bin
- /Users/perfektion/.rbenv/shims
- /Users/perfektion/.rbenv/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
Checking the gem path for the gem whois and i can see it located there.
Strangely though irb seems to be able to locate the gem:
~/ » irb
irb(main):001:0> require 'whois'
=> true
irb(main):002:0> whois = Whois::Client.new
=> #<Whois::Client:0x007fbc121074c8 #timeout=10, #settings={}>
I have been troubleshooting this for about 24 hours now and i feel like i am losing my mind. This issue has only become apparent in the past 24-48 hours. Prior to that the scripts i was playing with were working fine.
Potentially Useful Info
Running OSX Sierra 10.12.4
I am using rbenv and ruby-build
Using Ruby 2.4.1 set globally
PATH = /Users/perfektion/.rbenv/shims:/Users/perfektion/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Re-installed rbenv, ruby-build, ruby and removed all gems and re-installed.
I feel like it is something stupid, but can anyone see what i am doing wrong here that would be causing ruby to not be able to find these gems?
Thank you!
Update
Not sure why i didn't pick this up earlier, but in the top of my script i have:
#!/usr/bin/ruby
I am not sure why this worked before and it isn't now.
Thanks for the help everyone :)
Whenever you try to run the file it's looking for the gem in the Ruby 2.0 directory. Whenever you do gem env it's showing 2.4.1 as your ruby version.
Keep in mind that with rbenv you can either set a local, global, or shell level version of ruby to run: https://github.com/rbenv/rbenv#rbenv-local
You can also create a .ruby-version file in a directory, and rbenv will look for that and use that version if it exists. Something is off between which version of ruby you are using to install the gem and which one is being used to run your whois script.
when you type ./whois.rb you call the ruby system.
try use ruby ./whois.rb
It will call the RVM/rbenv loaded ruby system
Because ruby is trying to fetch the library from another path that is not the same as the one you installed the wois gem with rbenv. (What could be some conflict with rvm and rbenv, I do not know.)
Try to create a new folder, set ruby 2.4 locally with local rbenv <version> and then try to make require again.

Rails: I installed Ruby, now "bundle install" doesn't work

I’m using Rails 4.2.7. I downloaded an example that evidently requires me to use Ruby 2.1.6 rather than the Ruby 2.3.0 version I had installed …
localhost:lti_tool_provider_example-master davea$ bundle install
Your Ruby version is 2.3.0, but your Gemfile specified 2.1.6
So that’s what I did. However after installing Ruby 2.1.6, now “bundle install” doesn’t work …
localhost:lti_tool_provider_example-master davea$ rvm install ruby-2.1.6
Warning! PATH is not properly set up, '/Users/davea/.rvm/gems/ruby-2.3.0/bin' is not at first place,
usually this is caused by shell initialization files - check them for 'PATH=...' entries,
it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
to fix temporarily in this shell session run: 'rvm use ruby-2.3.0'.
Warning, new version of rvm available '1.27.0', you are using older version '1.26.11'.
You can disable this warning with: echo rvm_autoupdate_flag=0 >> ~/.rvmrc
You can enable auto-update with: echo rvm_autoupdate_flag=2 >> ~/.rvmrc
Searching for binary rubies, this might take some time.
Found remote file https://rubies.travis-ci.org/osx/10.12/x86_64/ruby-2.1.6.tar.bz2
Checking requirements for osx.
Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.
Requirements installation successful.
ruby-2.1.6 - #configure
ruby-2.1.6 - #download
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 7630k 100 7630k 0 0 1199k 0 0:00:06 0:00:06 --:--:-- 1551k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.1.6 - #validate archive
ruby-2.1.6 - #extract
ruby-2.1.6 - #validate binary
Libraries missing for ruby-2.1.6: cannot. Refer to your system manual for installing libraries
Mounting remote ruby failed with status 10, trying to compile.
Checking requirements for osx.
Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.
Requirements installation successful.
Warning: DYLD_LIBRARY_PATH environment variable is set, this might interact with the compilation and ruby.
Installing Ruby from source to: /Users/davea/.rvm/rubies/ruby-2.1.6, this may take a while depending on your cpu(s)...
ruby-2.1.6 - #downloading ruby-2.1.6, this may take a while depending on your connection...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 11.4M 100 11.4M 0 0 2272k 0 0:00:05 0:00:05 --:--:-- 2354k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.1.6 - #extracting ruby-2.1.6 to /Users/davea/.rvm/src/ruby-2.1.6....
ruby-2.1.6 - #configuring....................................................
ruby-2.1.6 - #post-configuration.
ruby-2.1.6 - #compiling.......................................................................................................................................
ruby-2.1.6 - #installing...............
ruby-2.1.6 - #making binaries executable..
ruby-2.1.6 - #downloading rubygems-2.4.8
ruby-2.1.6 - #extracting rubygems-2.4.8.....
ruby-2.1.6 - #removing old rubygems.........
ruby-2.1.6 - #installing rubygems-2.4.8......................
ruby-2.1.6 - #gemset created /Users/davea/.rvm/gems/ruby-2.1.6#global
ruby-2.1.6 - #importing gemset /Users/davea/.rvm/gemsets/global.gems...............................................
ruby-2.1.6 - #generating global wrappers........
ruby-2.1.6 - #gemset created /Users/davea/.rvm/gems/ruby-2.1.6
ruby-2.1.6 - #importing gemsetfile /Users/davea/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.1.6 - #generating default wrappers........
ruby-2.1.6 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.1.6 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri
localhost:lti_tool_provider_example-master davea$ bundle install
-bash: bundle: command not found
How do I restore the “bundle” command without interfering with the Ruby 2.1.3 version I just installed?
Bundle with Ruby 2.1.6
You just need to install bundler :
rvm use ruby-2.1.6
gem install bundler
This will be installed in a gemset specific to ruby-2.1.6, so it won't interfere with anything you installed with ruby-2.3.0. You can use
bundle install
to install the required gems.
Trying with Ruby 2.3.0
Alternatively, you could just try the example you downloaded with ruby-2.3.0 by either changing the
ruby '2.1.6'
line or deleting it from the Gemfile.
I experienced this same issue. For my case, the cause of the issue was because of two conflicting versions of the bundler gem that are very close in version number.
bundler (2.0.2, 2.0.1, default: 1.17.2)
The issue was from the bundler versions 2.0.2 and version 2.0.1
This is what I did to fix it.
Open your terminal or command line
Ctrl + Alt + T
N/B: The command above is for Linux Users, the one for Windows users might be different
Display a list of all your local gems for the bundler gem
gem list bundler
N/B: The command above is for rbenv version manager, the one for rvm might be different
Look through the displayed versions of the bundler gem, you will see some closely related conflicting versions like the one below
bundler (2.0.2, 2.0.1, default: 1.17.2)
Uninstall the bundler gem
gem uninstall bundler
Install a new copy of the bundler gem
gem install bundler
Try running the bundle install command again now
bundle install
That's all
I hope this helps.
Simply do the following
Open your terminal
Run gem uninstall bundler to uninstall previous versions of bundler
And then run gem install bundler to install a new copy of bundler
You can now run
bundle install
This worked for me
As mentioned above, you must re-install bundler gem again (because last one was and actually is attached to the previous version you had, as global library, you could actually go back and set it up as default again and see that bundler still there since usually all ruby versions you install thru version managers rbenv or rvm will be kept locally in your machine user's folder.
Step by step run the following (just in case)
rvm list known
Let's say ruby-2.3.3 is the latest or the one you want to work with
rvm install ruby-2.3.3
rvm use --default 2.3.3
gem install bundler
bundle install
In my case i was using OSX also rvm in OSX rvm store rubies in /Users/some_user/.rvm/rubies/default so just remember to configure whatever your terminal is with the proper rvm's ruby path in this case the file i should double check will be .bash_profile and the line of code i would look for will be export PATH=$PATH:/Users/some_user/.rvm/rubies/default
Hope this is helpful for someone that just realizes how rvm and rbenv work around, i was expecting somehow that bundler being a key part of the process will be more like a core library per se (ruby), but instead bundler is a totally separated gem, which bring me back to think, what a gem! way to go! inspirational one!

"ruby -v" no longer returning current version

In the process of trying to upgrade to Ruby 1.9.3, I think I broke something. I believe I have Ruby 1.9.3 successfully installed. However, now when I type ruby -v into terminal, I'm not getting any messages. Here's the sample output:
rish-macbookair:~ rish$ ruby -v
rish-macbookair:~ rish$
One of the last things I did was install the "Command Line Tools" in XCode because I was getting a "missing libraries" error.
Any ideas on what might have happened, or where to start?
Edit: upon trying to reinstall 1.9.3, I get this:
rish-macbookair:~ rish$ rvm reinstall 1.9.3
/usr/local/rvm/src/ruby-1.9.3-p327 has already been removed.
Removing /usr/local/rvm/rubies/ruby-1.9.3-p327...
https://rvm.io/binaries/osx/10.8/x86_64/ruby-1.9.3-p327.tar.bz2 - #configure
ruby-1.9.3-p327 - #download
ruby-1.9.3-p327 - #extract
ruby-1.9.3-p327 - #validate
ruby-1.9.3-p327 - #setup
sed: RE error: illegal byte sequence
Saving wrappers to '/usr/local/rvm/bin'.
ruby-1.9.3-p327 - #importing default gemsets (/usr/local/rvm/gemsets/), this may take time ...
Making gemset ruby-1.9.3-p327 pristine.
Making gemset ruby-1.9.3-p327#global pristine.
rish-macbookair:~ rish$
I have tried reinstalling RVM as well, but I'm back in the same place
you are using old version of rvm, try:
rvm get head
rvm reinstall 1.9.3
rvm use 1.9.3

Where are the GEMs when Ruby compiled manually in Mac OS X 10.6.8?

I manually built Ruby 1.9.2 on Snow Leopard. Now I can’t find my old GEM files. I’m guessing they're in a different path now or something. So I have three questions:
What is the "old" gem path, where gem install sinatra puts the sinatra gem?
What is the "new" gem path, which is set when I build Ruby manually?
How do I change it so Ruby finds my gems again?
Typing gem env (Using your old Ruby install's gem command) at a command prompt gives something similar to:
> RubyGems Environment:
> - RUBYGEMS VERSION: 1.3.6
> - RUBY VERSION: 1.9.1 (2009-07-16 patchlevel 243) [i386-mingw32]
> - INSTALLATION DIRECTORY: C:/Ruby19/lib/ruby/gems/1.9.1
> - RUBY EXECUTABLE: C:/Ruby19/bin/ruby.exe
> - EXECUTABLE DIRECTORY: C:/Ruby19/bin
> - RUBYGEMS PLATFORMS:
> - ruby
> - x86-mingw32
> - GEM PATHS:
> - C:/Ruby19/lib/ruby/gems/1.9.1
> - C:/Users/Username/.gem/ruby/1.9.1
> - GEM CONFIGURATION:
> - :update_sources => true
> - :verbose => true
> - :benchmark => false
> - :backtrace => false
> - :bulk_threshold => 1000
> - REMOTE SOURCES:
> - http://rubygems.org/
(On Windows... I imagine Snow Leopard will have a similar format)
The GEM PATHS field is the interesting thing here. If you go to those directories listed, you should see a folder named cache. That will contain a list of .gem files corresponding to all the installed gems in that specific directory. You should just be able to call gem install *gemname* on each of those gem files (using your new Ruby install's gem command).
EDIT: Mistakenly referred to INSTALLATION DIRECTORY instead of GEM PATHS. Greg reminded me that there are multiple locations known by a specific installation of Rubygems. All of those locations needs to be checked for gems used by that installation of Ruby.
Your "old" gems would be relative to the Ruby that came bundled with the Mac because the gem command is included with Ruby 1.8.7, which is stock on Snow Leopard. If your which ruby shows /usr/bin/ruby, your gem environments should be similar to:
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/greg/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
If you are using RVM you might be able to tell it to copy your gems from the system gemset to one under RVM's control. I haven't tried doing that as I install RVM immediately and let it handle all my Ruby installation and then I ignore the system's installation.
If your which ruby shows /usr/local/bin/ruby then the gem env command should reflect the changed path for the version you compiled from source.
I'm curious WHY you would build it manually, when RVM is available to handle all the configuration and installation, and largely remove any concerns about where things are and whether you've just stomped on the system's installed version.
When RVM has installed a Ruby version, it will all be in ~/.rvm and your Gems will be nicely located there too. You'll be able to manage the gems as gemsets, relative to each version of Ruby, and switch back and forth instantly. Or, even better, you can run a command/program in each version of Ruby you have installed to test them using rvm ruby 'some command'.
Notice in the above gem env output that gems are in three separate areas on the disk. Under RVM's control they're in RVM's sandbox:
- GEM PATHS:
- /Users/greg/.rvm/gems/ruby-1.9.2-p0
- /Users/greg/.rvm/gems/ruby-1.9.2-p0#global
That makes it trivial for me to back them up, or blow them away if I want to.
I used to compile my rubies from source on my Macs and Linux boxes. I use RVM for that now. It's so much better than doing it by hand.
I believe the standard gem install path on OS X is:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/

ruby gems under rvm on Ubuntu (failing to) install in the wrong location

I'm running Ubuntu 10.04 and originally installed ruby 1.9.1 (from source). I've just decided to try out ruby 1.9.2 and rails 3, and it seemed like a good time to use rvm to deal with the multiple ruby installs and gemsets.
rvm installed and seems to be working, I installed ruby 1.9.2 in rvm and made that my default ruby. However, every time I try to install a gem under ruby 1.9.2 I see this error.
mark#Steve-Austins-Penguin:~$ gem install haml
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /home/mark/.gem/specs
gem environment returns:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/mark/.rvm/gems/ruby-1.9.2-p0
- RUBY EXECUTABLE: /home/mark/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
- EXECUTABLE DIRECTORY: /home/mark/.rvm/gems/ruby-1.9.2-p0/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/mark/.rvm/gems/ruby-1.9.2-p0
- /home/mark/.rvm/gems/ruby-1.9.2-p0#global
<snip>
But if the correct installation, ruby and gem paths are showing here why is ruby trying to install gems to /home/mark/.gem? All the variables and paths shown by env look right, and I can't find a .gemrc file anywhere on my system that might contain conflicting path settings.
So I guess my question is what might be causing rubygems to attempt to install to /home/mark/.gems instead of the correct paths set by rvm?
In response to the question below:
mark#Steve-Austins-Penguin:~$ echo $PATH
/home/mark/.rvm/gems/ruby-1.9.2-p0/bin:/home/mark/.rvm/gems/ruby-1.9.2-p0#global/bin:/home/mark/.rvm/rubies/ruby-1.9.2-p0/bin:/home/mark/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
mark#Steve-Austins-Penguin:~$ which gem
/home/mark/.rvm/rubies/ruby-1.9.2-p0/bin/gem
mark#Steve-Austins-Penguin:~$ rvm list
rvm rubies
ruby-1.8.7-p302 [ x86_64 ]
=> ruby-1.9.2-p0 [ x86_64 ]
mark#Steve-Austins-Penguin:~$ env
rvm_gemsets_path=/home/mark/.rvm/gemsets
MANPATH=:/home/mark/.rvm/man
rvm_scripts_path=/home/mark/.rvm/scripts
rvm_bin_path=/home/mark/.rvm/bin
GEM_HOME=/home/mark/.rvm/gems/ruby-1.9.2-p0
rvm_patchsets_path=/home/mark/.rvm/patchsets
SHELL=/bin/bash
IRBRC=/home/mark/.rvm/rubies/ruby-1.9.2-p0/.irbrc
rvm_patches_path=/home/mark/.rvm/patches
MY_RUBY_HOME=/home/mark/.rvm/rubies/ruby-1.9.2-p0
rvm_selfcontained=1
USER=mark
__shell_array_start=0
rvm_gems_cache_path=/home/mark/.rvm/gems/cache
rvm_config_path=/home/mark/.rvm/config
rvm_path=/home/mark/.rvm
USERNAME=mark
rvm_gemset_separator=#
rvm_ruby_args=
rvm_rubies_path=/home/mark/.rvm/rubies
PWD=/home/mark
rvm_hooks_path=/home/mark/.rvm/hooks
rvm_version=1.0.1
rvm_src_path=/home/mark/.rvm/src
HOME=/home/mark
rvm_gems_path=/home/mark/.rvm/gems
rvm_ruby_string=ruby-1.9.2-p0
BUNDLE_PATH=/home/mark/.rvm/gems/ruby-1.9.2-p0
rvm_tmp_path=/home/mark/.rvm/tmp
LOGNAME=mark
GEM_PATH=/home/mark/.rvm/gems/ruby-1.9.2-p0:/home/mark/.rvm/gems/ruby-1.9.2-p0#global
rvm_action=list
rvm_log_path=/home/mark/.rvm/log
rvm_interactive=1
RUBY_VERSION=ruby-1.9.2-p0
rvm_archives_path=/home/mark/.rvm/archives
rvm_repo_path=/home/mark/.rvm/repos
_=/usr/bin/env
Note that I've edited down the response from env slightly - simply to keep the size of this post under control - by removing all the entries relating to X, GNOME and SSH.
Following up the backtrace from running gem install -V --backtrace --debug haml (thanks zzzhc) and taking a closer look at the /home/mark/.gem directory I found that there were no gems installed there, just gemspec files and gem source files. In the spirit of experimentation I deleted /home/mark/.gem and re ran the gem install command and suddenly it was working. And that it had recreated /home/mark/.gem containing gemspecs for the gems I'd just installed.
It's clear now that I'd misinterpreted the error message in the original question; rubygems didn't fail while trying to install gems to /home/mark/.gem, it was simply using that directory as a temporary store for the gemspecs of newly downloaded gems about to be installed. Before installing rvm I'd been installing gems onto the system using sudo gem install... which would have created the /home/mark/.gem directory with root permissions. So rubygems run without sudo was unable to access the temp directory to store gemspecs in and was aborting before it could install the gems. Doh!
Another way is type which gem after getting into the ruby version. You will get something like this - /home/username/.rvm/rubies/ruby-1.9.2-p180/bin/gem. Now just type sudo /home/username/.rvm/rubies/ruby-1.9.2-p180/bin/gem install gem_name.
Specifying the complete path and adding sudo work fine.
check the first line of /home/mark/.rvm/rubies/ruby-1.9.2-p0/bin/gem and look at http://yehudakatz.com/2010/08/24/a-tale-of-abort-traps-or-always-question-your-assumptions/

Resources