Wednesday, November 14, 2007

Building Ruby From Source On Nexenta

Currently Nexenta's package manager provides installations of Ruby 1.8.2 (the ruby package) and Ruby 1.8.4 (the ruby1.8 package). If you would like to build the latest version (1.8.6 as of this writing), these are instructions for the steps that I took beyond what is currently posted on the rubyonrails website. Keep in mind that your custom installation will not be available for update with the Synaptic package manager and may cause conflicts if you choose to install the version from the Nexenta repository, so you might want to consider overriding the default installation directory (in the directions, I specify --prefix=/usr/opt in the ruby_zone, but for the global zone, I tend to use $HOME as my installation path for non-Synaptic installations).

Install a Ruby on Rails Zone

Install a new zone called ruby_zone and login.

Build and Install Ruby From Source

  • root@ruby_zone:~# mkdir /usr/opt/sources
  • root@ruby_zone:~# cd /usr/opt/sources/
  • root@ruby_zone:/usr/opt/sources# wget http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6.tar.gz
  • root@ruby_zone:/usr/opt/sources# gunzip ruby-1.8.6.tar.gz
  • root@ruby_zone:/usr/opt/sources# tar -xf ruby-1.8.6.tar
  • root@ruby_zone:/usr/opt/sources# cd ruby-1.8.6
  • root@ruby_zone:/usr/opt/sources/ruby-1.8.6# apt-get install make gcc
  • root@ruby_zone:/usr/opt/sources/ruby-1.8.6# apt-get install zlib1g-dev (or else you will see an error that looks like remote_fetcher.rb:4:in `require': no such file to load -- zlib (LoadError) error when installing ruby gems)
  • root@ruby_zone:/usr/opt/sources/ruby-1.8.6# ./configure --prefix=/usr/opt --with-zlib-include=/usr/include --with-zlib-lib=/usr/lib
  • root@ruby_zone:/usr/opt/sources/ruby-1.8.6# make
  • root@ruby_zone:/usr/opt/sources/ruby-1.8.6# make test (expect to see a test succeeded message)
  • root@ruby_zone:/usr/opt/sources/ruby-1.8.6# make install

Setup Ruby Gems

  • root@ruby_zone:/usr/opt/sources/ruby-1.8.6# cd ..
  • root@ruby_zone:/usr/opt/sources# wget http://rubyforge.org/frs/download.php/20989/rubygems-0.9.4.tgz
  • root@ruby_zone:/usr/opt/sources# gunzip rubygems-0.9.4.tgz
  • root@ruby_zone:/usr/opt/sources# tar -xf rubygems-0.9.4.tar
  • root@ruby_zone:/usr/opt/sources# cd rubygems-0.9.4
  • root@ruby_zone:/usr/opt/sources/rubygems-0.9.4# /usr/opt/bin/ruby setup.rb
  • root@ruby_zone:/usr/opt/sources/rubygems-0.9.4# /usr/opt/bin/gem update (or else you may see Could not find rails (> 0) in any repository)

Install the Rails Gem

  • root@ruby_zone:/usr/opt/sources/rubygems-0.9.4# /usr/opt/bin/gem install rails --include-dependencies
  • root@ruby_zone:/usr/opt/sources/rubygems-0.9.4# mkdir /tmp/test_rails
  • root@ruby_zone:/usr/opt/sources/rubygems-0.9.4# /usr/opt/bin/rails /tmp/test_rails
  • root@ruby_zone:/usr/opt/sources/rubygems-0.9.4# cd /tmp/test_rails
  • root@ruby_zone:/tmp/test_rails# /usr/opt/bin/ruby script/server (expect WEBrick to start)

From a browser, open http://ipaddress.of.ruby_zone:3000 (I chose 192.168.0.115 as the ipaddress)

You should now see the Rails "Welcome aboard" screen!

Saturday, November 10, 2007

Unix Command To Delete Corrupted Subversion Meta-data

Did you ever find yourself in a situation where you have projects checked-out from source control and the directory-based source control meta-data (from CVS or Subversion) has somehow become irreparably corrupted (or the fix to the corruption is non-obvious)? You do not want to lose local working-copy changes, but because of the corruption you cannot rebuild the meta-data, re-connect to source control, or overlay freshly-updated project files from the source control system without the potential loss of your local workspace changes?
A solution to this problem is to delete only the project's meta-data directories, back-up the project files to a temporary directory, re-check out the project code from the source control system, and overlay the backed-up project files onto the pristine project (which has uncorrupted meta-data).

This is the simple Unix command I use for deleting all the Subversion meta-data in a directory and in its subdirectories:

  • find . -name .svn -type d -print | xargs rm -r -f

It is pretty straightforward to interpret what is happening with this command. It is finding any directory (-type d) named .svn in the current directory (.) and its subdirectories. Each of those directories is deleted (rm -r) without prompting (-f). -print | xargs can be interpretted as use each result from the find command as input to the rm command.

find is very robust in what it can take as input, so a more general version of this line could be rewritten as:

  • find </path/to/a/directory> -name <a_regex> -type <d | f> -print | xargs rm -r -f

It can then be used to delete from a branch of the filesystem heirarchy any files or directories whose names match some pattern.