I've become very interested in Ruby, primarily because of the promise of Rails. However don't let the advocates fool you: installing Rails into a non-standard location is anything but trivial due to complications with RubyGems. My environment is as follows:
- Mac OS X 10.4 (Tiger)
- Ruby 1.8.2 installed as part of standard Tiger installation in /usr
- RubyGems 0.8.10 (from http://www.rubygems.org/) in ~/Public/ruby
The goal is to create a Rails application called "rails" under the directory ~/Development/ruby-workspace, requiring the installation of RubyGems in ~/Development/rubygems-0.8.10. Below you will find an annotated list of the steps I took to accomplish this goal (or you can view the terminal session here: RubyGems, Rails Install.txt).
NOTE: While I now have a working Ruby/RubyGems/Rails installation, the newly created Rails application still cannot connect to my local MySQL server.
The first step was to download and extract the latest RubyGems distribution (version 0.8.10 at the time of writing) and run the installer. The installation script was launched using the --prefix=/Users/garnold/Development/rubygems-0.8.10 option to specify an alternate installation directory, however the post-install.rb script failed complaining about a permissions problem in /usr/lib/ruby/gems/1.8:
Last login: Sun May 8 22:27:55 on ttyp4
Welcome to Darwin!
Geoffrey-Arnolds-Computer:~ garnold$ cd ~/Public/ruby
Geoffrey-Arnolds-Computer:~/Public/ruby garnold$ unzip -q rubygems-0.8.10.zip
Geoffrey-Arnolds-Computer:~/Public/ruby garnold$ cd rubygems-0.8.10
Geoffrey-Arnolds-Computer:~/Public/ruby/rubygems-0.8.10 garnold$ ruby setup.rb all --prefix=/Users/garnold/Development/rubygems-0.8.10
---> bin
<--- bin
---> lib
---> lib/rubygems
<--- lib/rubygems
<--- lib
---> bin
<--- bin
---> lib
---> lib/rubygems
<--- lib/rubygems
<--- lib
rm -f InstalledFiles
---> bin
mkdir -p /Users/garnold/Development/rubygems-0.8.10/bin/
install gem /Users/garnold/Development/rubygems-0.8.10/bin/
install gem_server /Users/garnold/Development/rubygems-0.8.10/bin/
install gemwhich /Users/garnold/Development/rubygems-0.8.10/bin/
install generate_yaml_index.rb /Users/garnold/Development/rubygems-0.8.10/bin/
install update_rubygems /Users/garnold/Development/rubygems-0.8.10/bin/
<--- bin
---> lib
mkdir -p /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/
install gemconfigure.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/
install rubygems.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/
install ubygems.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/
---> lib/rubygems
mkdir -p /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install builder.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install cmd_manager.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install command.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install config_file.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install custom_require.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install dependency_list.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install deployment.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install doc_manager.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install format.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install gem_commands.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install gem_runner.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install installer.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install loadpath_manager.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install old_format.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install open-uri.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install package.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install remote_installer.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install rubygems_version.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install source_index.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install specification.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install timer.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install user_interaction.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install validator.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
install version.rb /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems
<--- lib/rubygems
<--- lib
As of RubyGems 0.8.0, library stubs are no longer needed.
Searching $LOAD_PATH for stubs to optionally delete (may take a while)...
...done.
No library stubs found.
Successfully built RubyGem
Name: sources
Version: 0.0.1
File: sources-0.0.1.gem
hook /Users/garnold/Public/ruby/rubygems-0.8.10/./post-install.rb failed:
You don't have write permissions into the /usr/lib/ruby/gems/1.8 directory.
Try 'ruby setup.rb --help' for detailed usage.
It seems that no matter what directory you specify with the --prefix option, RubyGems insists on installing files under /usr. This is troubling, but let's test the installation anyway:
Geoffrey-Arnolds-Computer:~/Public/ruby/rubygems-0.8.10 garnold$ cd ~/Development/rubygems-0.8.10
Geoffrey-Arnolds-Computer:~/Development/rubygems-0.8.10 garnold$ ./bin/gem install rails --install-dir=/Users/garnold/Development/rubygems-0.8.10/lib/ruby/gems./bin/gem:3:in `require': No such file to load -- rubygems (LoadError)
from ./bin/gem:3
Looks like Ruby cannot find the RubyGems libraries. The Ruby man page tells us to use the RUBYLIB environment variable to point Ruby to its extensions:
Geoffrey-Arnolds-Computer:~/Development/rubygems-0.8.10 garnold$ export RUBYLIB=/Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8:/Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby
Geoffrey-Arnolds-Computer:~/Development/rubygems-0.8.10 garnold$ ./bin/gem install rails --install-dir=/Users/garnold/Development/rubygems-0.8.10/lib/ruby/gemsAttempting local installation of 'rails'
Local gem file not found: rails*.gem
Attempting remote installation of 'rails'
/Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems.rb:194:in `report_activate_error': Could not find RubyGem sources (> 0.0.0) (Gem::LoadError)
from /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems.rb:136:in `activate'
from /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems.rb:37:in `require_gem_with_options'
from /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems.rb:31:in `require_gem'
from /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems/remote_installer.rb:403:in `sources'
from /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems/remote_installer.rb:413:in `source_index_hash'
from /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems/remote_installer.rb:377:in `install'
from /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems/gem_commands.rb:179:in `execute'
from /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems/gem_commands.rb:137:in `each'
from /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems/gem_commands.rb:137:in `execute'
from /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems/command.rb:49:in `invoke'
from /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems/cmd_manager.rb:92:in `process_args'
from /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems/cmd_manager.rb:65:in `run'
from /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:9:in `run'
from ./bin/gem:17
Now RubyGems is complaining about now being about to find the sources package (most likely something that would have been installed by the post-install.rb script). Therefore we must manually install the package from the gem included with the RubyGems distribution:
Geoffrey-Arnolds-Computer:~/Development/rubygems-0.8.10 garnold$ ./bin/gem install ~/Public/ruby/rubygems-0.8.10/pkgs/sources/sources-0.0.1.gem --install-dir=/Users/garnold/Development/rubygems-0.8.10/lib/ruby/gems
Attempting local installation of '/Users/garnold/Public/ruby/rubygems-0.8.10/pkgs/sources/sources-0.0.1.gem'
Successfully installed sources, version 0.0.1
Another attempt at installing Rails leads us back to the permissions problem, so we (begrudgingly) create the required directories:
Geoffrey-Arnolds-Computer:~/Development/rubygems-0.8.10 garnold$ ./bin/gem install rails --install-dir=/Users/garnold/Development/rubygems-0.8.10/lib/ruby/gemsAttempting local installation of 'rails'
Local gem file not found: rails*.gem
Attempting remote installation of 'rails'
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /usr/lib/ruby/gems
Geoffrey-Arnolds-Computer:~/Development/rubygems-0.8.10 garnold$ sudo mkdir /usr/lib/ruby/gems
Geoffrey-Arnolds-Computer:~/Development/rubygems-0.8.10 garnold$ ./bin/gem install rails --install-dir=/Users/garnold/Development/rubygems-0.8.10/lib/ruby/gems
Attempting local installation of 'rails'
Local gem file not found: rails*.gem
Attempting remote installation of 'rails'
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /usr/lib/ruby/gems/1.8
Geoffrey-Arnolds-Computer:~/Development/rubygems-0.8.10 garnold$ sudo mkdir /usr/lib/ruby/gems/1.8
Finally Rails can be installed:
Geoffrey-Arnolds-Computer:~/Development/rubygems-0.8.10 garnold$ ./bin/gem install rails --install-dir=/Users/garnold/Development/rubygems-0.8.10/lib/ruby/gems
Attempting local installation of 'rails'
Local gem file not found: rails*.gem
Attempting remote installation of 'rails'
Install required dependency rake? [Yn]
Install required dependency activesupport? [Yn]
Install required dependency activerecord? [Yn]
Install required dependency actionpack? [Yn]
Install required dependency actionmailer? [Yn]
Install required dependency actionwebservice? [Yn]
Successfully installed rails-0.12.1
Successfully installed rake-0.5.4
Successfully installed activesupport-1.0.4
Successfully installed activerecord-1.10.1
Successfully installed actionpack-1.8.1
Successfully installed actionmailer-0.9.1
Successfully installed actionwebservice-0.7.1
Installing RDoc documentation for rake-0.5.4...
Installing RDoc documentation for activesupport-1.0.4...
Installing RDoc documentation for activerecord-1.10.1...
Installing RDoc documentation for actionpack-1.8.1...
Installing RDoc documentation for actionmailer-0.9.1...
Installing RDoc documentation for actionwebservice-0.7.1...
Now we attempt to create our sample application called "rails":
Geoffrey-Arnolds-Computer:~/Development/rubygems-0.8.10 garnold$ ./lib/ruby/gems/bin/rails /Users/garnold/Development/ruby-workspace/rails
/Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems.rb:194:in `report_activate_error': Could not find RubyGem rails (> 0) (Gem::LoadError)
from /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems.rb:136:in `activate'
from /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems.rb:37:in `require_gem_with_options'
from /Users/garnold/Development/rubygems-0.8.10/lib/ruby/site_ruby/1.8/rubygems.rb:31:in `require_gem'
from ./lib/ruby/gems/bin/rails:17
The RubyGems manual instructs us to use the GEM_PATH environment variable to specify the location of installed gems. With this variable set the application can be created:
Geoffrey-Arnolds-Computer:~/Development/rubygems-0.8.10 garnold$ export GEM_PATH=/Users/garnold/Development/rubygems-0.8.10/lib/ruby/gems
Geoffrey-Arnolds-Computer:~/Development/rubygems-0.8.10 garnold$ ./lib/ruby/gems/bin/rails /Users/garnold/Development/ruby-workspace/rails
create
create app/apis
create app/controllers
create app/helpers
create app/models
create app/views/layouts
create config/environments
create components
create db
create doc
create lib
create log
create public/images
create public/javascripts
create public/stylesheets
create script
create test/fixtures
create test/functional
create test/mocks/development
create test/mocks/test
create test/unit
create vendor
create Rakefile
create README
create CHANGELOG
create app/controllers/application.rb
create app/helpers/application_helper.rb
create test/test_helper.rb
create config/database.yml
create config/routes.rb
create public/.htaccess
create config/environment.rb
create config/environments/production.rb
create config/environments/development.rb
create config/environments/test.rb
create script/console
create script/console_sandbox
create script/destroy
create script/generate
create script/server
create script/runner
create script/benchmarker
create script/profiler
create script/breakpointer
create public/dispatch.rb
create public/dispatch.cgi
create public/dispatch.fcgi
create public/404.html
create public/500.html
create public/index.html
create public/favicon.ico
create public/javascripts/prototype.js
create doc/README_FOR_APP
create log/server.log
create log/production.log
create log/development.log
create log/test.log
Geoffrey-Arnolds-Computer:~/Development/rubygems-0.8.10 garnold$ cd ~/Development/ruby-workspace/rails
Geoffrey-Arnolds-Computer:~/Development/ruby-workspace/rails garnold$ ruby script/generate controller sample
exists app/controllers/
exists app/helpers/
create app/views/sample
exists test/functional/
create app/controllers/sample_controller.rb
create test/functional/sample_controller_test.rb
create app/helpers/sample_helper.rb
Geoffrey-Arnolds-Computer:~/Development/ruby-workspace/rails garnold$ ruby script/server
=> Rails application started on http://0.0.0.0:3000
[2005-05-08 22:42:26] INFO WEBrick 1.3.1
[2005-05-08 22:42:26] INFO ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]
[2005-05-08 22:42:26] INFO WEBrick::HTTPServer#start: pid=1390 port=3000
127.0.0.1 - - [08/May/2005:22:43:09 EDT] "GET /sample HTTP/1.1" 200 13
- -> /sample