RVM install ruby-1.8.7-p330 fails

Today I’m thinking of getting back into so good old work and I read there is a new patch to Ruby, version p330. So I figure that RVM (Ruby Version Manager) being so easy and quick to update, I’d do the good old “rvm get head, rvm reload, rvm update 1.8.7″ and I’m off to the races.

Well it wasn’t quite as simple. I ended up with an error:
ruby-1.8.7-p330 - #fetching
ruby-1.8.7-p330 - #extracting ruby-1.8.7-p330 to /Users/andrew/.rvm/src/ruby-1.8.7-p330
ruby-1.8.7-p330 - #extracted to /Users/andrew/.rvm/src/ruby-1.8.7-p330
ruby-1.8.7-p330 - #configuring
ruby-1.8.7-p330 - #compiling
Error running 'make ', please read /Users/andrew/.rvm/log/ruby-1.8.7-p330/make.log
There has been an error while running make. Halting the installation.

When I looked into the the make.log, It had this to say:
readline.c: In function ‘username_completion_proc_call’:
readline.c:730: error: ‘username_completion_function’ undeclared (first use in this function)
readline.c:730: error: (Each undeclared identifier is reported only once
readline.c:730: error: for each function it appears in.)

So, I figured this was going to take too long to deal with, and moved on to working on my projects. That is till I opened up my project and and did a “rvm 1.8.7@rails3″ and it come up with:
warn: ruby ruby-1.8.7-p330 is not installed.
To install do: 'rvm install ruby-1.8.7-p330'

Great! Now I can’t upgrade, and I can’t work with what I have!

Long story short, I figured out that I was missing readline (now I’m sure I’ve installed in a long while ago, but I think I was missing the latest version). Also, rvm install readline resulted in an “Unrecognized command line argument: ‘readline’ ( see: ‘rvm usage’ )

Turns out RVM updated it’s command to install readline to:
rvm package install readline

Update: (Nov 10, 2011)
If you’re using a newer version of RVM, package has been renamed to pkg, so the command to install readline would be:
rvm pkg install readline

However this didn’t fix my install issue, still got the same error. Luckily I found a post that pointed out that my rvm may not know where readline is (odd, as I used rvm to install readline). Running this command allowed me to install it correctly:
rvm install 1.8.7 -C –with-readline-dir=/Users/andrew/.rvm/usr
[Notice: 'andrew' is my username on my mac, yours might be different]

rvm install 1.8.7 -C --with-readline-dir=$rvm_path/usr

Like always, I’m hoping this helps some people out.

Let me know if you have any issues.

Learn More

Stripping ASCII colour from a ruby string

I spent a few good hours trying to figure out how to strip a coloured ruby string:

Coloured Ruby String

which comes out as this:

>> p t
"2 scenarios (e[33m2 undefinede[0m), 7 steps (e[36m2 skippede[0m, e[33m3 undefinede[0m, e[32m2 passede[0m)"
=> nil

Now I tried to gsub the string and remove the colour using a RegEx like this:

> t.gsub(/\e[(d+)m/, "")
=> "2 scenarios (e[33m2 undefinede[0m), 7 steps (e[36m2 skippede[0m, e[33m3 undefinede[0m, e[32m2 passede[0m)"

But as you can see, nothing changed. After reading a whole lot of docs on Ruby, Googling around and reading the Ruby String class I came to this conclusion:

>> b = "e[33m"
=> "e[33m"
>> b.each_byte{|c| puts c}
27
91
51
51
109
=> "e[33m"
>> "" << 27 #The only way I know how to add ASCII codes to string
=> "e"

Now what this allowed me to do is figured out the ASCII code for the e character. However because normally you escape the back slash on regular expressions, once I figured out e was a valid character, I got this:

>> "e[33m".gsub(/e[(d+)m/, '')
=> ""

I hope this saves someone a few hours!

Learn More

Installing/Updating SQLite3 on Windows

Installing SQLite3 DLL

To install SQLite3 in windows you require not only the gem but a DLL files in your system PATH (or in your windows/system32 folder).

To obtain the DLL, go to: http://www.sqlite.org/download.html

I always believe that DLLs belong in the windows/system32 folder but as long as you put yours somewhere where your PATH environment variable points to, you should be fine.

Installing/Updating the SQLite3 Gem

Normally to install the gem you’d call gem install sqlite3-ruby and it would do everything automatically but if you try it (as of today) it will give you the following error:

C:>gem install sqlite3-ruby
Building native extensions. This could take a while...
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.

c:/ruby/bin/ruby.exe extconf.rb install sqlite3-ruby
checking for fdatasync() in rt.lib... no
checking for sqlite3.h... no

nmake
'nmake' is not recognized as an internal or external command,
operable program or batch file.

Gem files will remain installed in
c:/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4 for inspection.
Results logged to
c:/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4/ext/sqlite3_api/gem_make.out

As not helpful as that error message is, it turns out that the new version of sqlite3-ruby doesn’t have a win32 version (which is needed for it to install/function correctly). So all you have to do is specify an older version of sqlite3.

To install a older version of a gem, run:

gem install --version 1.2.3 sqlite3-ruby

Now you’re all set to go!

Once sqlite3 is installed and you try to update the rest of your gems calling gem update, it will fail because (as of September 8th) sqlite3-ruby doesn’t have a win32 version of the 1.2.4 gem. To get around this, remove the sqlite3-ruby gem (gem uninstall sqlite3-ruby), then call gem update and then reinstall the gem by calling gem install –version 1.2.3 sqlite3-ruby.

SOURCE:

The most helpful site online that helped me figure this out was: http://www.ruby-forum.com/topic/164116

UPDATE:

I just tired updating the gems myself and had to uninstall sqlite3-ruby (it seems as of October 21st, 2008, they still haven’t fixed the issue!) and I copied the command of my own blog to find it doesn’t work. Not sure if it’s just firefox or wordpress but the problem is in the way the page is rendered, the “- – version” has a double dash (without the space) but the browser changes the html and makes it one dash. So I attempted to put it in a different format. So for those who had issues before, you can now copy the code above and just make sure that the version has a double dash in front of it.

Learn More