28 June 2007

Getting the latest netbeans ruby-ide automatically

Update 12/11/2007: Blogger had completly destroyed the formatting of the code, I had a received a few emails telling me the script did not work. I have once again copy pasted it and it should work, I apologize if I have wasted your time, I should really move to a serious blogging system !!!

Update 10/04/2008: THE SCRIPT DOES NOT WORK ANYMORE. The Netbeans changed their nightly build system, you can download the latest version and install netbeans manually from http://bits.netbeans.org/download/trunk/nightly/latest/

I am using netbeans since april 2007 as my primary Rails editor on Linux ubuntu. I used to work with Radrails (now Aptana) because I used to be a java developper and work with Eclipse.

When RadRails "dissapeared", I started looking for alternative IDEs and so far I am very happy with netbeans.

Tor Norbye and his team are very active (and responsive!) and keep delivering new features all every week! The only way to use these features - as far as I am concerned - is to download the latest build from the Continuous Integration server at http://deadlock.netbeans.org/hudson/job/ruby/

To save a bit of time, I have written a script to install the latest netbeans ruby-ide automatically. You need to install the mechanize gem first.

This script will:
  • connect to the Continuous Integration server of sun (http://deadlock.netbeans.org/hudson/job/ruby/)
  • Guess what's the latest stable build file name and download it to a temp location (depending on your OS)
  • rename the old install
  • unzip the build to the netbeans installation folder
  • delete the downloaded zip from the tmp location

You need to install mechanize:

gem install mechanize

Hten, copy the following code to a ruby file and adapt the last two lines to your configuration. The 1st paramater is the "netbeans installation folder" and the
second one your tmp folder.


script = NetbeansUpdaterScript.new("/home/jeanmichel/ruby/programs", "/tmp")


require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'mechanize'
require 'fileutils'

class GenericScript
def download_from(url, save_as)
mechanize = WWW::Mechanize.new
puts "downloaded " + url + " and saved to " + save_as

def remove(file_or_directory)
FileUtils.remove_dir(file_or_directory, true) if File.directory?(file_or_directory)
FileUtils.rm file_or_directory if File.file?(file_or_directory)
puts "remove " + file_or_directory

def unzip_file(file, target_dir)
"unzip", "-q", file, "-d", target_dir
) or raise "Error extracting (#{$?}): unzip #{file.inspect} -d #{target_dir.inspect}"
puts "unzip " + file + " to " + target_dir

def is_using_mac?
RUBY_PLATFORM == /darwin/


class NetbeansUpdaterScript < tmp_folder = "/tmp" netbeans_installation_folder =" netbeans_installation_folder" netbeans_folder_path =" @netbeans_installation_folder" tmp_folder =" tmp_folder" netbeans_installer_file =" @tmp_folder" doc =" Hpricot(open(" last_stable_build_number =" doc.inner_html" last_stable_build_number=" + @last_stable_build_number.to_s @last_stable_build_number end def url_latest_build get_last_stable_build_number if is_using_mac? " script =" NetbeansUpdaterScript.new(">

I have used this script for a week and it seems to work alright but I'd be happy to hear some feedback about the code or any problem you might have.


Anonymous said...

ok so now that i have this code what do i do with it? i'm very new to ruby/netbeans

Anonymous said...

line 35 ?
line 61 : extra 'end'

apparently, something is missing ...

Jean-Michel said...

Hello anonymnous!
I really hater blogger because it's destroying the formaating of the code ... I have copy-pasted the code one more time, it should be fine.
Contact me if you have any doubt (look inside the rounded corner at the top left hand corner of this blog)

Jan Wikholm said...

a small patch for your ruby script.

< FileUtils.mv @netbeans_folder_path, @netbeans_folder_path + "-previous"
> FileUtils.mv @netbeans_folder_path, @netbeans_folder_path + "-previous" if File.exists? @netbeans_folder_path

This mainly deals with users who are running the script for the very first time.

Patch can also be found here:


Anonymous said...

Thanks, just switching from Aptana/RadRails... need autotest, etc.

lamyseba said...

Where can i find the open-uri gem?

~$ gem install open-uri does not work
~$ gem q -r -n open-uri

rest-open-uri (1.0.0)
A drop-in replacement for open-uri for use in REST clients.

Any Idea?

Jean-Michel said...

open-uri is part of standard ruby, you only need to install mechanize: gem install mechanize