How-To: Add Ruby-on-Rails to XAMPP

Problems with the Linux version of XAMPP, questions, comments, and anything related.

How-To: Add Ruby-on-Rails to XAMPP

Postby greno » 28. December 2010 17:50

This is a true integration of Ruby-on-Rails into XAMPP. (Not just using the version of Ruby found on the OS.)

Backup your current installation:
Code: Select all
cd /opt
sudo tar czf /tmp/xampp-current.tgz lampp

To create a good Ruby on Rails working environment for XAMPP we need to set some environment variables:
Code: Select all
echo "
export PATH=/opt/lampp/sbin:/opt/lampp/bin:/opt/lampp:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"  # loads Ruby Version Manager (RVM) into a shell session.
" > ~/.bashrc_xampp_ruby

# do this for 'root' user as well as regular user
# plus I would recommend you add XAMPP into your $PS1 prompt somewhere

Now source this file in every shell where you want to use Ruby on XAMPP:
Code: Select all
source ~/.bashrc_xampp_ruby

To install Ruby-on-Rails in XAMPP:
Note: do this in a separate dedicated terminal window since we are setting ENV vars.
Code: Select all
 sudo -s   # or su -
 dirname $(which mysql)   # must show  '/opt/lampp/bin'  else you forget to source ~/.bashrc_xampp_ruby
 yum install libyaml ruby-tcltk  # yum example, change as necessary for your packager;  tcltk requires nativethreads enabled
 cd /opt/lampp

 # to use latest snapshot:
 # wget
 # tar xzf stable-snapshot.tar.gz -C /opt/lampp
 # cd ruby/
# OR to use latest tarball:
 tar xzf ruby-1.9.2-p136.tar.gz -C /opt/lampp
 cd ruby-1.9.2-p136/

 ./configure --prefix=/opt/lampp --enable-shared
 export INCLUDE_PATH=/opt/lampp/include:/usr/include
 export LD_LIBRARY_PATH=/opt/lampp/lib:/usr/lib/:/usr/local/lib:/var/lib
 export LD_RUN_PATH=/opt/lampp/lib:$LD_RUN_PATH
 export APXS2=/opt/xampp/bin/apxs
 export PATH=/opt/lampp/bin:/opt/lampp/sbin:/opt/lampp/libexec:$PATH
 sudo make install

 # test installation:
 which ruby  # should show /opt/lampp/bin/ruby if your PATH is setup right
 ruby -v
 ruby -ropenssl -rzlib -rreadline -e "puts :Hello"
 exit   # back out of sudo / root

To install Rails Gem in XAMPP:
Code: Select all
sudo gem install rails

To install MySQL Gems:
Code: Select all
sudo gem install mysql mysql2

Create a Rails project:
Code: Select all
 sudo -s   # or su -
 mkdir -p /opt/lampp/var/ruby/rails
 cd /opt/lampp/var/ruby/rails
 rails new WelcomeAboard -d mysql
 cd WelcomeAboard
 rails server -p 8000

browser to: http://localhost:8000




Posts: 54
Joined: 04. October 2006 19:25

Re: How-To: Add Ruby-on-Rails to XAMPP

Postby ksager » 22. February 2011 07:03

Hi Gerry, Thank you for this tutorial. I did manage to achieve the Welcome Aboard screen thanks to your instructions.
I progress to your test screen - produce that, and then check the ruby version to confirm. Everthing's good! ;-)

One hang-up on Ubuntu 10.10, with a system Ruby-full of 1.8.7 installed beforehand:
The 'sudo gem install mysql mysql2' refused to complete without errors (a fresh Ubuntu 10.10 installation). After some research, I settled upon:

'aptitude install libmysqlclient-dev'

which then allowed the 'sudo gem install mysql mysql2' to operate correctly; and all of your subsequent instructions completed. Also, with the system Ruby 1.8.7,
the "yum install libyaml ruby-tcltk" was not necessary...Unless something is lurking yet to bite me! Thanks again for the tutorial. I'm graduating to "Add Ruby RVM, Rack and Passenger(mod_rails) to XAMPP" by grino next!
Regards, Kyle
Posts: 3
Joined: 14. February 2011 19:21

Re: How-To: Add Ruby-on-Rails to XAMPP

Postby hansBKK » 24. March 2011 18:17

Maybe I'm confused, but it seems to me that you're just using XAMPP's MySQL server, not the Apache server. I believe the "rails server" command is actually running a separate http daemon called "Webrick", which isn't very respected in anything but testing/demo scenarios.

My understanding from my googling so far, is that it's best to use the Mongrel http server rather than Webrick. Some people don't like having to spec the weird port address (in your example the :8000), so a virtual host in XAMPP could do a 2-way proxy.

There's also an Apache module called phusion passenger that might work, haven't got into that too much.
Posts: 6
Joined: 22. April 2007 12:33
Location: Bangkok

Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 5 guests