Ruby not picking up .gemrc - ruby

I'm having trouble running a gem on system ruby -- I've done the install, and the gem runs when rvm runs 1.9.2, but doesn't run on rvm system, though that too is 1.9.2. The OS is OSX 10.6.8.
One importance difference seems to be GEM_HOME, as seen in rvm info. This is set for rvm 1.9.2, to values in ~/.gemrc, but not set for rvm system.
So at a guess, the system ruby isn't reading the .gemrc file.
Is there anyway to verify this?
How can I correct it?
The system ruby was installed from source.
The gem in question is compass, version 0.12.1. An install of 0.11.5 also failed.
Also, gem -v is 1.5.3. That's a rollback, I was using 1.8.24 but that too failed and I rolled back to a prior to see if that helped.

The system Ruby doesn't know about any gems you've installed in RVM managed Rubies, nor will it care about a .gemrc file.
The system Ruby stands alone, and for most purposes should be left as it was installed by Apple unless you reeeeeeally know why it's there and what it affects. Apple had their own reasons for installing Ruby and at least one app installed by Apple by default on a Mac OS machine requires it. We're free to use it, but deleting it will break that app, and updating it could cause problems that possibly won't surface immediately, so I think it's best to just ignore it.
If I need a system-wide Ruby for a Mac, I'd install it from source into /usr/local/bin, which is the appropriate place for a replacement. For my own development, I use RVM or rbenv, and let them install in my home directory, which is their default. That way I'm free to mess around to my heart's content, and even blow them away, without any chance of affecting the system.
By the way, the version of Ruby isn't important, it's what installed it and where it's installed.

Related

Best way to update all of RVM rubies and gems after system update?

I'm seeking a more streamlined and robust approach to keeping my rvm environment intact after an OS update. I'm using Mountain Lion, rvm 1.18.16 and homebrew, which has readline, gettext, libxml2, libxslt, qt, gtk+ -- the gems that usually break for me are nokogiri and capybara-webkit
Twice now after updating Mountain Lion and XCode, my native extension gems and Ruby have suffered breakage and I have to spend time getting everything working again. I have to wonder if I'm following the best practice for getting all the rvm components updated after such system update.
What typically happens is that gems with native extensions are linking against old libraries that are no longer available, especially with the libxml issues surrounding Mountain Lion. Here's the basic steps I take to get my system back online across all projects (I have about 8 versions of Ruby installed under rvm, so this is tedious!).
First, update Mountain Lion and XCode via the App Store.
Second, Update homebrew with:
brew update
brew upgrade
Then list your rubies and start recompiling each one with...
rvm list
rvm reinstall ruby-1.9.2-p290
rvm reinstall ruby-1.9.3-p392
...
NOTE: I did try:
rvm all do reinstall
but that gave me this error: "reinstall: command not found"
Next up, step through each ruby and perform pristine on the gems (this has side effect of recompiling all native extension gems):
rvm use ruby-1.9.3-p392
gem pristine --all
Finally, go to each project and perform the following:
bundle install
I'm not sure if that last step is strictly necessary -- some projects seemed to be ok, some weren't, but running this seemed to clear up last remaining issues.
Surely there's a more streamlined way to manage this process!? I've only been using both Mountain Lion and rvm for a couple months, but in that time, two system updates have killed most of my working Ruby environment. I have a lot of Ruby versions installed because of my job as a consultant and encountering many development environments, so I'd really like to get this down to an easily repeatable process.
Any thoughts? Can the above be further improved?
You can do:
rvm reinstall all
append --force to skip the questions.
Note that will do full reinstall including gem pristine of every gem, you need to pay attention to the output as it will notify you about the gems that failed to executes the pristine action.

What is the point of installing the same version of Ruby through RVM as the system Ruby?

I've been using the default system ruby version 1.8.7 without RVM for a few rails projects and have not run into any problems. I just recently installed RVM, and after running rvm requirements I get this output:
To use an RVM installed Ruby as default, instead of the system ruby:
rvm install 1.8.7 # installs patch 357: closest supported version
rvm system ; rvm gemset export system.gems ; rvm 1.8.7 ; rvm gemset import system.gems # migrate your gems
rvm alias create default 1.8.7
I believe what these commands do are to install the same gems that have already been installed using the system ruby under the RVM installed ruby.
My questions are, am I right in what these commands do? and if I am right, why is it important to do this, because if I wanted to use an RVM installed Ruby of a different version like 1.9.2, wouldn't it already separate gems in that version from the system's ruby?
The one thing that springs to mind is, if you use the system Ruby, you'll use it slightly differently that RVM's Rubies--for example, you'll likely need to use sudo to install gems. Furthermore, you won't be able to use many of RVM's features, like gemsets, with the system Ruby.
Well one reason I can think of is that you don't wanna worry about your system not working even if the system ruby gets updated.
My questions are, am I right in what these commands do?
You are right in what they do. The first command installs Ruby 1.8.7, the second command installs all the gems currently install on your system Ruby installation in the new RVM Ruby 1.8.7 installation, and the third command sets your default version of Ruby to be the RVM Ruby 1.8.7.
and if I am right, why is it important to do this, because if I wanted to use an RVM installed Ruby of a different version like 1.9.2, wouldn't it already separate gems in that version from the system's ruby?
The second command is actually more of about convenience than necessity. Yes, the gems install in the RVM 1.8.7 will be completely separate from the ones installed in the system version of Ruby; however, if you didn't run the second command, you're RVM 1.8.7 would start out with almost no gems (only the defaults). That means that you would need to go through and manually install the gems that you need to get your project up and running. Instead of doing that, the second command allows you to just install the same gems you've already installed in the system version of Ruby to the RVM 1.8.7 version—it doesn't migrate them, it just makes a copy of them. After the second command, there are two distinct sets of the exact same gems: one in the system Ruby and one in the RVM 1.8.7 Ruby. So, if you were to update gems in either of the Rubies, they would get updated, but the other version's gems would be unaffected.
Hope this helps answer your question.

gem install LibXML-Ruby Native extension fails to build under RVM 1.9.2

I am trying to gem install libxml-ruby under RVM's 1.9.2-p0 on a Snow Leopard installation. The build process of the native extension, however, halts with this error:
~/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/mkmf.rb:368:in 'try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
I'm not sure where exactly to start in terms of debugging this issues, but if anyone has a hint at a solution, I would much appreciate it. Here is a full dump of the log: https://gist.github.com/3b13bf6f66f5bd6033ca.
The message:
You have to install development tools first.
means you don't have Apple's XCode development environment installed. You can download it from Apple's XCode site with a free registration.
The XCode environment is also included with the Snow Leopard DVD, but it was buggy, so download the latest version.
Your question isn't exactly clear though. RVM isn't anywhere near a 1.9.2 release, so I think you mean "Ruby 1.9.2-p0". If so, then I'm not sure how you got Ruby installed under RVM's control without the development environment unless... did you run sudo or su to root before trying to install LibXML? If so, that is potentially the problem as you're never supposed to install gems under RVMs control using sudo if you're running a single-user version of RVM.
If you're sure all your existing RVM and Ruby and XCode are good, try rvm package install libxml2.
Also, as a safety tip, remember to periodically run rvm get head to make sure its current. I run it every other day, but weekly or monthly should be good.

ruby 1.9.2 installation and gems

I have installed Ruby 1.9.2 from source. But it seems there is some trouble recognizing the bundler gem which I have already installed.
My /etc/environment file:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ruby/bin"
It looks like my gems are in /usr/local/ruby/gems/1.9.1/gems/.
In my rails application when I attempt to run sudo bundle install I get an error:
sudo: bundle: command not found
Also, why do the directories say 1.9.1?
Type which ruby to see the path your system thinks ruby is in.
Did you use a --prefix=... option for configure when you set up the configuration? Normally Ruby from source wouldn't be in /usr/local/ruby/bin. The Ruby executable would be in /usr/local/bin/ruby, but that is not how you'd set up your PATH to use it, so that looks suspicious. Notice that your path already contains /usr/local/bin so if Ruby installed into the normal location for a source-installation, that path will pick it up and your final search of /usr/local/bin/ruby will be wrong and unnecessary.
If you installed the gem before you installed the new version of Ruby then the gem would be part of the previous installation, not the current one, and wouldn't be visible to it. They're separate installs.
Unless you are trying to do a system-wide install for multiple users there is no real reason to compile from source and allow it to install to /usr/local/bin. I highly recommend installing RVM, then letting it install any Ruby versions into RVM's ~/.rvm sandbox. Gems will also be installed relative to the currently enabled RVM controlled ruby, which is a really good thing.

How to update Ruby to 1.9.x on Mac?

I have created a new user account on my mac and I am trying to update to the current version of ruby on it (1.9.2) from the snow leopard default of 1.8.7. Can somebody point me to tutorial or explain the best method to update Ruby on my mac from 1.8 to 1.9.2? Thanks
As The Tin Man suggests (above) RVM (Ruby Version Manager) is the Standard for upgrading your Ruby installation on OSX: https://rvm.io
To get started, open a Terminal Window and issue the following command:
\curl -L https://get.rvm.io | bash -s stable --ruby
( you will need to trust the RVM Dev Team that the command is not malicious - if you're a paranoid penguin like me, you can always go read the source: https://github.com/wayneeseguin/rvm ) When it's complete you need to restart the terminal to get the rvm command working.
rvm list known
( shows you the latest available versions of Ruby )
rvm install ruby-2.3.1
For a specific version, followed by
rvm use ruby-2.3.1
or if you just want the latest (current) version:
rvm install current && rvm use current
( installs the current stable release - at time of writing ruby-2.3.1 - please update this wiki when new versions released )
Note on Compiling Ruby: In my case I also had to install Homebrew Link to get the gems I needed (RSpec) which in turn forces you to install Xcode (if you haven't already) https://itunes.apple.com/us/app/xcode/id497799835 AND/OR install the GCC package from: https://github.com/kennethreitz/osx-gcc-installer to avoid errors running "make".
Edit: As of Mavericks you can choose to install only the Xcode command line tools instead of the whole Xcode package, which comes with gcc and lots of other things you might need for building packages. It can be installed by running xcode-select --install and following the on-screen prompt.
Examples: https://rvm.io/workflow/examples/
Screencast: http://screencasts.org/episodes/how-to-use-rvm
Note on erros: if you get the error "RVM is not a function" while trying this command,
visit: How do I change my Ruby version using RVM? for the solution.
I'll make a strong suggestion for rvm.
It's a great way to manage multiple Rubies and gems sets without colliding with the system version.
I'll add that now (4/2/2013), I use rbenv a lot, because my needs are simple. RVM is great, but it's got a lot of capability I never need, so I have it on some machines and rbenv on my desktop and laptop. It's worth checking out both and seeing which works best for your needs.
With brew this is a one-liner:
(assuming that you have tapped homebrew/versions, which can be done by running brew tap homebrew/versions)
brew install ruby193
Worked out of the box for me on OS X 10.8.4. Or if you want 2.0, you just brew install ruby
More generally, brew search ruby shows you the different repos available, and if you want to get really specific you can use brew versions ruby and checkout a specific version instead.
I know it's an older post, but i wanna add some extra informations about that.
Firstly, i think that rvm does great BUT it wasn't updating ruby from my system (MAC OS Yosemite).
What rvmwas doing : installing to another location and setting up the path there to my environment variable ... And i was kinda bored, because i had two ruby now on my system.
So to fix that, i uninstalled the rvm, then used the Homebrew package manager available here and installed ruby throw terminal command by doing brew install ruby.
And then, everything was working perfectly !
The ruby from my system was updated !
Hope it will help for the next adventurers !
I'll disagree with The Tin Man here. I regard rbenv as preferable to RVM. rbenv doesn't interfere drastically with your shell the way RVM does, and it lets you add separate Ruby installations in ordinary folders that you can examine directly. It allows you to compile Ruby yourself. Good outline of the differences here: https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F
I provide instructions for compiling Ruby 1.9 for rbenv here. Further, more detailed information here. I have used this technique with easy success on Snow Leopard, Lion, and Mountain Lion.
Dan Benjamin's Hivelogic article Installing Ruby, RubyGems, and Rails on Snow Leopard is the recommended place to go although the article is for 1.8, so here's a Ruby 1.9-specific install on Snow Leopard. Watch out for the 64-bit thing... either go all 64-bit 'fat' (as is - for example - Apache on OS X, which can cause problems with 32-bit libraries) or check any gems you're likely to use to make sure they're okay for 64-bit.
This command actually works
\curl -L https://get.rvm.io | bash -s stable --ruby
As previously mentioned, the bundler version may be too high for your version of rails.
I ran into the same problem using Rails 3.0.1 which requires Bundler v1.0.0 - v1.0.22
Check your bundler version using: gem list bundler
If your bundler version is not within the appropriate range, I found this solution to work: rvm #global do gem uninstall bundler
Note: rvm is required for this solution... another case for why you should be using rvm in the first place.
There are several other version managers to consider, see for a few examples and one that's not listed there that I'll be giving a try soon is ch-ruby. I tried rbenv but had too many problems with it. RVM is my mainstay, though it sometimes has the odd problem (hence my wish to try ch-ruby when I get a chance). I wouldn't touch the system Ruby, as other things may rely on it.
I should add I've also compiled my own Ruby several times, and using the Hivelogic article (as Dave Everitt has suggested) is a good idea if you take that route.

Resources