Archive for the ‘Ruby’ Category

Installing JRuby on Ubuntu

Today we will see how to install JRuby on Ubuntu

First of all you need to download the JRuby. Download the latest JRuby accessing the link:

http://dist.codehaus.org/jruby/

I am using the version 1.3.1 (jruby-bin-1.3.1.tar.gz)

Open a terminal and go to the directory where you have downloaded file and unpack the jruby file using the following command:

$ tar zxvf jruby-bin-1.3.1.tar.gz

We need to set some environment variables. I will add the following line at end of file .bashrc in your home directory.

export JRUBY_HOME=/home/leonardo/jruby-1.3.1
export PATH=$JRUBY_HOME/bin:$PATH

Now, Let’s check whether JRuby is installed properly, type the command:

$ jruby -v

You should see something like this:

jruby 1.3.1 (ruby 1.8.6p287) (2009-06-15 2fd6c3d) (Java HotSpot(TM) Client VM 1.6.0_13) [i386-java]

Alright! If you are able to see the JRuby version, your system is configured properly.

Now you can start installing some gems:

$ jruby -S gem install jruby-openssl

jruby-openssl is necessary due JRuby doesn’t support the default Ruby’s openssl.

The parameter -S tells JRuby to use the scripts which are in JRuby’s bin directory, then in a second case to use the which ones in the system PATH.

If you want to install Rails:

$ jruby -S gem install rails

That’s all about!

Advertisements

Installing Ruby on Ubuntu

This post will teach you how to install the Ruby on Ubuntu.

So, open your terminal and type the following commands:

$ sudo apt-get install ruby1.8 ruby1.8-dev irb1.8 rdoc1.8 ri1.8

Now, lets install RubyGems:

$ wget http://rubyforge.org/frs/download.php/57643/rubygems-1.3.4.tgz
$ tar xvzf rubygems-1.3.4.tgz
$ cd rubygems-1.3.4
$ sudo ruby1.8 setup.rb

The above command will install the RubyGems version 1.3.4

Lets now create some links to make the use of Ruby easy:

$ sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
$ sudo ln -s /usr/bin/ruby1.8 /usr/bin/ruby
$ sudo ln -s /usr/bin/rdoc1.8 /usr/bin/rdoc
$ sudo ln -s /usr/bin/ri1.8 /usr/bin/ri
$ sudo ln -s /usr/bin/irb1.8 /usr/bin/irb

That’s all! Now you can start using Ruby!

I will teach you how to install Rails on the next post.

All the best,

Leo

Warbler 0.9.9 default servlet filter config doesn’t work with Websphere 6.1

Many people have been facing some issue when trying to deploy a JRuby on Rails package using Warbler on WebSphere AS 6.1.

One workaround is to copy the file JRUBY_HOME/lib/ruby/gems/1.8/gems/warbler-0.9.9/web.xml.erb to your app/config diretory and change it to use a Servlet instead of a Filter as below:

<!DOCTYPE web-app PUBLIC

“-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN”

  "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
  <% webxml.context_params.each do |k,v| %>
  <context-param>
      <param-name><%= k %></param-name>
      <param-value><%= v %></param-value>
  </context-param>
  <% end %>

  <listener>
      <listener-class><%= webxml.servlet_context_listener %></listener-class>
  </listener>

  <servlet>
      <servlet-name>Rails</servlet-name>
      <servlet-class>org.jruby.rack.RackServlet</servlet-class>
  </servlet>

  <servlet-mapping>
      <servlet-name>Rails</servlet-name>
      <url-pattern>/*</url-pattern>
  </servlet-mapping>

  <% if webxml.jndi then webxml.jndi.each do |jndi| %>
  <resource-ref>
      <res-ref-name><%= jndi %></res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>
  <% end; end %>
</web-app>

Also instead of changing the web.xml.erb file to use Servlet you can configure your WebSphere AS to work with Rack Filter. To do that you have to:

1. Start the Websphere server and open the Administration Console
2. Set a Websphere web container custom property com.ibm.ws.webcontainer.invokefilterscompatibility = true.

If you have some difficult to find where to set this configuration tell me and I will give you the step-by-step.

I hope this tip be useful for everyone that is getting to work with JRuby On Rails on WebSphere.

All the best,

Leo