While Red Hat Enterprise Linux is known for its stability and flexibility, you might not think of it first when looking for the latest version of your web application framework. If you're a developer working with Ruby and Ruby on Rails, you probably want to take advantage of their new features. Sure, you can use RVM, but sometimes you just want to get supported system packages.
Software Collections (often abbreviated as SCL) allows you to run more recent versions of software than what ships with your current version of Red Hat Enterprise Linux. This article will show you how to start development of a Rails 3.2 application running on Ruby 1.9.3 - all on RHEL 6, using only RPM packages, alongside your default Ruby installation. This tutorial assumes that you are familiar with Ruby on Rails basics, such as creating a new application and using bundler. It is also beneficial (although not necessary) to understand how Software Collections work in general.
Installing the ruby193 Collection
Throughout this tutorial, we will be using the ruby193 SCL. To get started, we will need to add it to Yum repositories. Grab a copy of the repofile and put it in /etc/yum.repos.d/
Now you can install all the packages needed for creating a Rails 3.2 application just by running (with proper privileges, of course)
yum install ruby193
While this takes some time, you'll have all the packages that you need for this exercise.
Kickstarting a New Application
Now that the collection is installed, you can create a new Rails application. It is important to note that all Ruby-related commands must be run in the SCL enabled environment. Otherwise they will not work or may trigger unexpected behavior.
You can run Ruby-related commands in the SCL enabled environment in two ways.
1. Run every command in SCL enabled environment like this:
scl enable ruby193 "ruby -v"
2. Run a subshell (more convenient and comfortable) that will be SCL enabled itself:
scl enable ruby193 "bash"
In this subshell, you can run any command as you normally would without having to remember to use "scl enable"
for every command. Don't forget to enable the SCL every time you run anything that needs Ruby (e.g. rspec, minitest, rails, ...).
To create a new application called "app", you need to issue the command:
rails new app
This will create a standard Rails 3.2 application with one small change in the way that Bundler is run.
Bundler Trouble
Normally, when creating a new Rails application, the generator calls "bundle install"
, which results in installing the newest versions of all Gems; this would render the SCL packaged Gems useless, as most of them would be rendered obsolete by newer versions and not be used. If you are choosing the collection for development, you probably don't want that. The default generator has been altered to run "bundle install --local"
, which utilizes the newest local versions of Gems (the ones from the collection). If you don't like this setup, you can always delete app/Gemfile.lock
and run "bundle install"
in the app directory to get the newest versions.
Generally, if you want to start using a new Gem that is part of the collection (run "yum list 'ruby193-*'"
to see the complete list, not all are installed by default), you have to
- install it with Yum (
"yum install ruby193-rubygem-foo"
) - add it to
Gemfile
- run "
bundle install --local"
.
If you want to use a classic Gem from rubygems.org, you only need to add it to Gemfile
and run "bundle install"
.
Running the Application
Now that the application is created, you can try to run it. Use:
cd app
rails s
You will get an error message containing this string:
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
Why? Rails developers have made a decision not to assume what JavaScript engine you want to use. There are number of these: therubyracer, therubyrhino, NodeJS... The ruby193 collection contains therubyracer, so we will use it (it gets installed with the collection, so you don't need to install it separately). Open Gemfile
in your favorite text editor and uncomment the line that reads:
# gem 'therubyracer', :platforms => 'ruby'
Next run "bundle install --local"
again. Now try running the development server again:
rails s
Success! You can now go to http://0.0.0.0:3000/ to see the title page of your new Ruby on Rails 3.2 application on RHEL 6. Everything is set, so you can start coding just as you are used to.
Last updated: November 2, 2023