Monthly Archives: December 2007

Building Ruby 1.9.0 on an Apple Mac

I decided to start playing around with the latest Ruby, 1.9.0, which was released on Christmas Day.  I am on a MacBook Pro running OSX Tiger 10.4.11.

I previously blogged about what to do with Ruby 1.9 to get up-to-speed. Anyone using Ruby today probably shouldn’t be considering overwriting their Ruby 1.8.6 installation if they do any real coding or have an existing code base. Many of the gems and libraries you use may not work with 1.9, Rails 2.0.2 for one does not.

Getting Started

The first thing I did was download the Ruby 1.9 source from Ruby-Lang, ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.0-0.tar.gz. I copied the contents of this archive to a folder in my home directory called Source (/Users/rbazinet/Source). This way I keep all of my downloaded source organized and easy to manage.

Opening up a Terminal window and changing to that directory will get things started. Now to setup the build to not overwrite my installed version 1.8.6 of Ruby, I created a directory called ruby19 in my home directory.

$ autoconf
$ ./configure --prefix=/Users/rbazinet/ruby19
$ make

Of course nothing always works as planned. During the build I received the following error:

compiling readlinegcc -I. -I../../.ext/include/i686-darwin8.11.1 -I../.././include -I../.././ext/readline -DRUBY_EXTCONF_H=\"extconf.h\"    -fno-common -g -O2 -pipe -fno-common   -o readline.o -c readline.c
readline.c: In function 'filename_completion_proc_call':
readline.c:659: error: 'filename_completion_function' undeclared (first use in this function)
readline.c:659: error: (Each undeclared identifier is reported only once
readline.c:659: error: for each function it appears in.)
readline.c:659: warning: assignment makes pointer from integer without a cast
readline.c: In function 'username_completion_proc_call':
readline.c:684: error: 'username_completion_function' undeclared (first use in this function)
readline.c:684: warning: assignment makes pointer from integer without a cast
make[1]: *** [readline.o] Error 1
make: *** [all] Error 1

It appears readline is the problem here and needs to be updated. After a bit of searching around the net I can across some information about this and determine readline needs to be updated to readline 5.2.

Readline can be downloaded from Gnu.org. I created a directory in my standard Source folder called readline-5.2 and then performed a build:

$ cd /User/rbazinet/Source/readline-5.2
$ ./configure --prefix=/usr/local
$ make
$ sudo make install

Now with Readline 5.2 installed I tried the Ruby 1.9 build again, this time indicating the location of my new Readline installation:

$ autoconf
$ ./configure --prefix=/Users/rbazinet/ruby19 --with-readline-dir=/usr/local
$ make
$ make install

Changing to our new Ruby 1.9 installation directory:

$ cd /Users/rbazinet/ruby19/bin
$ ./ruby -v
ruby 1.9.0 (2007-12-25 revision 14709) [i686-darwin8.11.1]
$

Success!

We could add our new ruby/bin to path if we wanted, to make it a big easier to test, but for now this works.  I am running Tiger so I don’t know if this same procedure works on Leopard.  If someone can confirm if this works or can comment on how to build Ruby 1.9 on Leopard, I will update this post to reflect what is needed to be done.

Technorati Tags: ,,

Ruby 1.9 Released – Should you use it today?

Ruby Logo

Ruby 1.9 was released on Christmas, announced on the Ruby web site. Matz made the announcement we all expected, as Matz seems to enjoy giving all the Rubyists a nice Christmas present.

Many developers probably were anxious for the release and wanted to download it, get it setup and start using their Ruby or Rails applications with some new found speed improvements. Anyone who has been around the computer industry for any amount of time knows it is rarely easy just to take a new release of a programming language and just use it with existing code or framework.

Dave Thomas has some nice insight on the topic of using Ruby 1.9 and whether it is right for you.

The Good:

  • Performance: this new Ruby runs on the new YARV virtual machine. For most compute-intensive applications, you’ll see significant speed improvements.
  • Support for string encodings and transcoding. Every string in Ruby can now have an associated encoding (ASCII, UTF-8, SJIS, and so on). You can transcode the contents of a string (for example converting ISO-8859-1 to UTF-8).
  • Integrated RubyGems and rake
  • Cool new goodies such as Fibers

The Bad:

  • This is a development release, not a production release. It has known bugs, and there’ll be more to come.
  • It contains several incompatible changes (block parameters are now block-local, String is no longer Enumerable, “cat”[1] now returns “a”, rather than 65)
  • It is more rigorous that 1.8 when it comes to detecting invalid code. For example, 1.8 accepts /[^\x00-\xa0]/u, while 1.9 complains of invalid multibyte escapes

Some of the things Rails developers expect today is that things normally just work and we take a lot for granted. Many of the existing gems and libraries do not work with Ruby 1.9, this includes Rails 2.0.2. Users have reported creating a new Rails application does not work property.

What’s the purpose of Ruby 1.9 then?

Well, it’s a development release so how about use it for development? This means developers who have created gems or libraries for Ruby should be taking advantage of this early release and get their products to work with 1.9.

It is also made available for hard-core Ruby developers to learn what’s new and how to use the new features, to play around with now. This does not mean you should be using it for production code, there are known bugs and there will be more found.

Users should install Ruby 1.9 as a secondary Ruby install, not an install over the top of your production Ruby 1.8.x or whatever. Dave Thomas gives a nice tutorial on the subject:

$ autoconf
$ ./configure --prefix=/Users/dave/ruby19
$ make
$ make install

Then, I just add /Users/dave/ruby19/bin to my path, and I'm using my nicely sandboxed version of Ruby 1.9.

$ PATH=/Users/dave/ruby19/bin:$PATH$ ruby -v
ruby 1.9.0 (2007-12-26 revision 0) [i686-darwin8.11.1]

This method will give you a sandbox or Ruby 1.9 to write code with and explore.

So, should it be used today?

The answer is yes and no. Yes, so you can play around with it, get to know it and update your libraries or gems if you maintain any. The other side of the argument is that you should not expect to use it for production code, it’s not meant for that today.

Ruby has come a long way and the future is bright. The performance improvements alone is reason enough to want to get it and learn it.

Technorati Tags: ,

Instant Rails 2.0 Released on RubyForge

I have been working hard on getting the latest and greatest components of Instant Rails 2.0 put together into a  coherent release to RubyForge.  It has been a bit more time consuming bringing it all together, learning the components of the project, learning more about Subversion than I knew already as well as how the whole process of working with RubyForge really happens. 

Being part of the open source community feels good and it feels good giving back to something I am passionate about.

It was very smooth for the most part, but trying not to mess up what already worked is what I am hoping for, so since this is my first work on an open source project from a commiter’s role, please be kind.  If there issues please submit them to the Instant Rails list or as a comment on this blog post.

Instant Rails 2.0 includes:
  • Ruby 1.8.6 Patch Level 111 with tons of bug fixes and new updated gems
  • Ruby on Rails 2.0.2
  • RubyGems 1.0.1
  • Rake 0.8.0
  • Mongrel 1.1.2
  • SQLite3

SQLite3 is included in this release since Rails 2.0.2 uses it by default.  Users should notice the Cookbook example uses the latest Rails 2.0.2 changes and has been updated to use SQLite3.

Instant Rails 2.0 can be downloaded from RubyForge now, please take a look at the Release Notes to see all the updates.

I will have some additional updates to the project over the next weeks.  I plan to post want I am going to update and hopefully I will receive the kind of feedback my readers have been providing.  Thank you all!

My David Heinemeier Hansson Rails 2.0 Interview up on InfoQ

I had the opportunity to interview David Heinemeier Hansson, Ruby on Rails creator,  recently for InfoQ and it went live today.  I was very impressed with David’s willingness to talk to me given the interview occurred right after the Rails 2.0 release.  I am sure I was not the only one pursuing him for an interview at the time.

You can check out the full interview, Talking Rails 2.0 with David Heinemeier Hansson, at InfoQ.

Setting up SQLite3 for Ruby on Rails Development

UPDATE: Thanks to an astute reader, it seems to have full SQLite3 support on Windows you need to add the SQLite3.dll and the SQLite3.def files also in your path.  I put these in my ruby/bin folder, which is where they will be in the Instant Rails release coming up.

The release of Ruby on Rails 2.0.2 made some fairly significant changes in the default database for Rails applications.  The default, and standard, database has always been MySql but the Rails team felt it easier for development to use SQLite3 and make it the new default.

Setting up SQLite3 is pretty straight forward both on Windows and the Mac OSX, both Tiger and Leopard come with SQLite3 already installed so that makes the Mac one up on Windows.  My Tiger installation had SQLite3 v3.13 installed on it so I wanted to make sure I had the latest at the time of this writing and put 3.5.4 on it.

Installing on Windows

The installation on Windows was really straight forward.  The main thing is to download the pre-compiled version of SQLite3 3.5.4 from the SQLite web site, unzip it and copy the single sqlite3.exe to my ruby/bin directory.

Now that SQLite3 is installed, just install the gem:

gem install sqlite3-ruby

And that’s it.

Installing/Updating on the Apple Mac OSX

Upgrading my Rails installation was a breeze on my MacBook Pro, after upgrading to RubyGems 1.0 the Rails 2.0.2 install went through without a hitch.  The only real concern I had about upgrading to Rails 2.0.2 on the Mac was the fact the default database for 2.0.2 is SQLite3 and I had an old version.  I feel a bit indifferent about installing over versions of software installed by Apple in the event it is used by something and I break it.  I am pretty new to the Mac and fixing an issue like this can sometimes be intimidating.

I found an older version of SQLite3, here:

/usr/local/bin/sqlite3

There are several ways to update software like this on the Mac and using MacPorts seems to be a popular way to do it, but I chose to install from source.   I have a Source directory in my home folder on my Mac and I simply start everything from there.  So, to install I did the following:

$ curl -O http://www.sqlite.org/sqlite-3.5.4.tar.gz
$ tar xzf sqlite-3.5.4.tar.gz
$ cd sqlite-3.5.4
$ ./configure --prefix=/usr/local
$ make
$ sudo make install

After working with Windows systems for most of my professional career I chuckle at how cryptic the commands are in Unix-like environments.  Maybe this is to keep the barrier to entry high.

Using the “which sqlite3” command should reveal the same location as the original SQLite3 installation.  If you actually type in “sqlite3” you enter the command mode of SQLite3 and should see the new 3.5.4 version.

The last step to is to install the Ruby driver for SQLite3, accomplished with:

$ sudo gem install sqlite3-ruby

This installed without any problems and was good to go with using SQLite3 on my Mac Rails 2.0.2 installation.  It’s funny though, the Windows installation was very easy and the Mac install took a bit of work that was not particularly obvious.  I thought the Mac was supposed to be so much easier than the PC?  Isn’t this what the Apple ads try to get us to believe?  I guess Apple just has better marketing.

Technorati Tags: ,,,

RubyGems 1.0 Released, Helps Windows Developers

UPDATE: Make that RubyGems 1.0.1, released tonight.

The great folks at the RubyGems project have released RubyGems 1.0.  This release fixes a bunch of issues, including some important ones for Windows developers.  Updates include:

Major New Features Include:

  • RubyGems warns about various problems with gemspecs during gem building
  • More-consistent versioning for the RubyGems software

Other Changes Include:

  • Fixed various bugs and problems with installing gems on Windows
  • Fixed using gem server for installing gems
  • Various operations are even more verbose with—verbose
  • Built gems are now backwards compatible with 0.9.4
  • Improved detection of RUBYOPT loading rubygems
  • ruby setup.rb now has a—help option
  • Gem::Specification#bindir is now respected on installation
  • Executable stubs can now be installed to match ruby’s name, so if ruby is installed as ‘ruby18’, foo_exec will be installed as ‘foo_exec18’
  • gem unpack can now unpack into a specific directory with—target
  • OpenSSL is no longer required by default

Deprecations and Deletions:

  • Kernel#require_gem has been removed
  • Executables without a shebang will not be wrapped in a future version, this may cause such executables to fail to operate on installation
  • Gem::Platform constants other than RUBY and CURRENT have been removed
  • Gem::RemoteInstaller was removed
  • Gem::Specification#test_suite_file and #test_suite_file= are deprecated in favor of #test_file and #test_file=
  • Gem::Specification#autorequire= has been deprecated
  • Time::today will be removed in a future version

It’s pretty simple to update your current RubyGems installation, simply type:

gem update --system

The upcoming release of Instant Rails 2.0 will include this new version of RubyGems, primarily because of the issues 0.95 users experienced on Windows.  Please read the official announcement on this RubyGems release which will help with other ways to update or install RubyGems on your system.

Technorati Tags: ,

links for 2007-12-20

  • A cool idea for hosting your Rails applications. You can even edit your code on-line.
    (tags: rails hosting)
  • A great utility for managing your gems, especially when going to production.
    (tags: rails gems)
  • Nice plugin for manager database configuration in a .rb file. This allows switching between databases pretty easily.
    (tags: plugin rails)