When I install a gem, it gets installed in a directory named 1.9.1, despite that not being the version of Ruby I have installed:
$ ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]
$ gem which rails
.../ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails.rb
Why does this happen? I have no other Ruby versions installed (and certainly not v1.9.1).
Note that the following is also for all later Ruby versions as of this writing, not just 1.9.2.
Per the 1.9.2 release announcement:
Standard library is installed in /usr/local/lib/ruby/1.9.1
This version is a "library compatible version." Ruby 1.9.2 is almost 1.9.1 compatible, so the library is installed in the 1.9.1 directory.
Even though it is installed in a differently-numbered directory, it is using 1.9.2. RubyGems can show all the directories it’s using via gem env.
This ensures that a set of installed gems is only used by versions that they can actually run with (especially due to compiled C extensions), and that when upgrading to a newer, but “library compatible”, version, one doesn’t have to reinstall all gems.
I believe it's because they share the same standard library.
There were some significant upgrades in the 1.9.2 core, but I don't think anything in the standard library was changed, so they share the same path. It's nothing to worry about, though — as you said, everything is working fine.
Related
I am using macOS Big Sur. When I check if Ruby is available, I see:
$ ruby -v
ruby 2.6.3p62
Checking with which:
$ which ruby
/usr/bin/ruby
I can see Ruby is pre-installed on macOS. But I've been told, "Do not use the system Ruby." Why?
Don't use the system Ruby!
Here are reasons not to use it for developing with Ruby:
the default location for gems is the system Ruby directory /Library/Ruby/Gems/2.6.0 so you will need to be superuser to install gems (and you really shouldn't alter this folder)
you could use sudo to install gems but that's a security risk (gem installation can run malicious code)
using Bundler is a best practice to manage gem versions and dependencies (projects might use different gem versions; or a project might use different gems that need different versions of a common dependency)
you could install Bundler with the --user-install argument to set the gem directory but that's not a common practice
it's best to start projects with the newest version of Ruby and the system Ruby is 2.6.3
if you've got multiple projects and can't update them all at once, you'll need multiple Ruby versions and a version manager (see my guide Install Ruby on a Mac that compares version managers and shows how to install Ruby with asdf or chruby or Homebrew)
the pre-installed Ruby is deprecated by Apple and may disappear in future macOS releases
Some developers use the system Ruby for running sysadmin scripts. That's fine, as long as you don't alter the system Ruby by attempting to update or adding gems. Remember, the system Ruby is there for macOS, not for you. For development, install Ruby with Homebrew or a version manager.
I just installed Ruby 2.0.0 using rbenv and set it to the global ruby version for my system. Since 2.0 is compatible with 1.9.3, I tried to start up a Rails project with it, but got the following error. I did rbenv rehash after installing 2.0
The `rails' command exists in these Ruby versions:
1.9.3-p327
Does this mean that every gem I installed on my system with 1.9.3 has to be reinstalled if I wish to use it with 2.0?
As seen here:
You need to reinstall bundler for each version of Ruby you use. See Ruby versions where you have it installed:
rbenv whence bundle
See your current version:
rbenv version
Install bundler for that version, if missing:
gem install bundler
Yes. Rbenv (and RVM) have separate "gem home" directories for each installed version of Ruby. There may be ways to symlink certain directories to get them to share, but this will likely lead to problems, particularly with gems that include native C extensions, which may or may not compile and run cleanly in multiple versions.
If you have a Gemfile, easiest thing is to just bundle install again for Ruby 2.0, giving you duplicate copies of many gems and Ruby-2.0 compiled versions of any native gems.
Another solution to this is to copy (or reinstall) the gems from your previous version to the newly installed version. How to do that is answered in detail in this question, which has two scripts -- one to install from local cache, one to reinstall from the internet (mine).
When I install a gem, it gets installed in a directory named 1.9.1, despite that not being the version of Ruby I have installed:
$ ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]
$ gem which rails
.../ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails.rb
Why does this happen? I have no other Ruby versions installed (and certainly not v1.9.1).
Note that the following is also for all later Ruby versions as of this writing, not just 1.9.2.
Per the 1.9.2 release announcement:
Standard library is installed in /usr/local/lib/ruby/1.9.1
This version is a "library compatible version." Ruby 1.9.2 is almost 1.9.1 compatible, so the library is installed in the 1.9.1 directory.
Even though it is installed in a differently-numbered directory, it is using 1.9.2. RubyGems can show all the directories it’s using via gem env.
This ensures that a set of installed gems is only used by versions that they can actually run with (especially due to compiled C extensions), and that when upgrading to a newer, but “library compatible”, version, one doesn’t have to reinstall all gems.
I believe it's because they share the same standard library.
There were some significant upgrades in the 1.9.2 core, but I don't think anything in the standard library was changed, so they share the same path. It's nothing to worry about, though — as you said, everything is working fine.
I'm trying to install RubyGems on a Fedora-based distribution that only has Ruby 1.8.6. I downloaded the RubyGems 1.6.2 package, unzipped and ran
$ ruby setup.rb
It bombs out with the rather unhelpful error message:
./lib/rubygems/custom_require.rb:54: warning: parenthesize argument(s) for future version
./lib/rubygems/custom_require.rb:57:in `require': undefined method `end_with?' for "no such file to load -- Win32API":String (NoMethod\
Error)
from ./lib/rubygems/config_file.rb:55
from ./lib/rubygems/custom_require.rb:36:in `gem_original_require'
from ./lib/rubygems/custom_require.rb:36:in `require'
from ./lib/rubygems/gem_runner.rb:8
from ./lib/rubygems/custom_require.rb:36:in `gem_original_require'
from ./lib/rubygems/custom_require.rb:36:in `require'
from setup.rb:25
Looking at the source of the exception, it seems that it first tries:
require "etc"
Etc.sysconfdir
and when that throws a NoMethodError it tries to require Win32API (which I assume isn't present on linux).
I'm guessing that this could be because I have an old version of Ruby, but I can't find the RubyGems version requirements documented anywhere. Can anyone suggest how to proceed with this?
How about installing RVM? Then you can manage multiple Ruby versions easily and, maybe, install a more recent version of Ruby. It works really well.
It is definitely possible to install RubyGems on Ruby 1.8.6, but not RubyGems 1.6.2. Support for Ruby 1.8.6 was dropped in RubyGems 1.4.0.
Why are you trying to circumvent your Linux distribution's package manager? They test interoperability between the packages they ship precisely to avoid situations like this.
In general, it is not a good idea to mix different package management systems. Ideally, you shouldn't be using RubyGems at all, when using Linux, since most distribution's package management systems are as good as RubyGems anyway. RubyGems is only needed on operating systems like Windows or OSX which are still stuck in the 1980s.
Thats what I do on my Redmine installation, for example: I just use the distribution packages of Rails, RedCloth, RMagick, Rack, Redmine, Ruby Enterprise Edition, Phusion Passenger, and whatever else I need. I don't even have RubyGems installed at all, neither from a distribution package nor from source.
If, however, for some reason, you need RubyGems, then you should move your entire Ruby environment out of the distribution package manager and manage it yourself. Just install whatever version and flavor of Rubinius, JRuby, IronRuby, YARV or whatever you want, install the latest version of RubyGems from source (or don't, since all of the above already ship with one pre-installed anyway) and install all of your Ruby libraries as Gems.
As was noted in other answers, RVM can be of help, but is generally unnecessary unless you want to manage multiple Ruby installations on the same machine.
You can't install RubyGems greater than 1.3.5 if you only have Ruby version 1.8.5.
RubyGems requires at least Ruby 1.8.6 to install.
My background:
- I have RubyGems 1.3.5 installed in
my CentOS Linux because Ruby is 1.8.6.
- What I did with Mac OS X, which comes
with Ruby 1.8.7, is to upgrade gem
from version 1.3.5 to version 1.6.2
by using the original gem.
What version of Ruby should I be using on a windows environment?
I'm trying to use Watir on 1.9 and it does not work. Will work on 1.8.6.
Any recomendations on which version to use and reasons why Watir does not work on 1.9
Watir.com recommends using Ruby 1.8.6-26. I have not tried it, but there is a fork of Watir that claims to be compatible with Ruby 1.9:
http://github.com/vapir/vapir
I use this one and it works:
>ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
There's no "correct" version. 1.8.6, 1.8.7 and 1.9.1 are all officially "recommended", which is not much help!
When 1.8.x gems don't work with 1.9.x under Windows, it's often the case that the gem - or one of its dependencies - includes a compiled element (a DLL, usually named with a .so extension) and that this component hasn't yet been compiled against mingw32, which is the standard for Ruby 1.9, whereas 1.8.6 and previous versions were compiled with the (old) MS Visual C.
Looking at the watir gem, I see it includes win32ole.so, which could be the problem. I'm not sure why that should have been necessary - it's part of the installed set for Windows. Perhaps the developers needed to ensure a fixed stable version so they forced a particular version rather than use the one from the library. Or maybe they fixed something? Dunno.
Beyond that, watir also depends on win32-api and nokogiri, both of which installed mswin32 versions on my machine and will need to have mingw32 versions to work with 1.9.
Not having a 1.9 instance to hand, I can't quickly tell if these versions exist.
Try looking for a mingw32 version of win32ole.so (probably somewhere like [ruby-dir]/lib/ruby/1.9/i386-mingw32) and putting it in place of the one used by watir.
It's best to use the mingw versions of Ruby as supplied with the RubyInstaller. The older mswin32 versions of Ruby are considered legacy. Some gems need to be compiled from source (RedCloth being a good example) and for this you'll need to install the DevKit; however, watir doesn't need anything to be compiled - all of its gem dependencies come pre-compiled with mingw32 extensions (nokogiri and win32-api).
You can install multiple versions of Ruby (including JRuby and IronRuby) on Windows using Pik. Once you've installed the Pik gem, you can easily install new versions of ruby by issuing commands such as pik install ruby 1.9.1 or pik install jruby. You can even do pik install devkit to install the DevKit for all installed copies of Ruby. Documentation and lots of examples of use can be found here.
To allow Watir (and FireWatir) to run on ruby 1.9.2
install devkit and follow procedures listed here : http://rubyinstaller.org/downloads/ Ruby Installer at GitHub
gem uninstall win32-api
gem install win32-api --platform=ruby