running rails + ruby + arch linux arm on raspberry pi 3

I’ve been asked to create a web monitoring application running on a Raspberry Pi (in this case the 3). The requirements are very modest; run a low-traffic web page to monitor another machine next to it, and provide a simple web report on demand across local WiFi. For this particular project I’ve elected to go back in time, as it were, and install Ruby and Rails as the web foundation. And when I say back in time, I’m talking 2007, when I created another embedded system using a milliwatt CMOS 486 clone chip running a custom built Linux kernel with µclib and BusyBox running Ruby and Rails.

This small post documents the steps, in order, for installing Ruby and Rails peculiar to Arch Linux ARM and the Raspberry Pi 3.

First, make sure that Ruby is installed. That’s as simple as ‘sudo pacman -S ruby’, and for the documentation, ‘sudo pacman -S ruby-docs’. Ruby Gems are a part of Ruby, and you can look to see if they’ve been installed with either a ‘gem -v’ or by looking down /usr/lib/ruby.

Second, add the following line to your .bashrc:

  • export PATH=”$(ruby -e ‘print Gem.user_dir’)/bin:$PATH”

Log out, then log back in. Make sure to do all this before you install Rails, or else Very Bad Things will happen when you do install Rails. It took two attempts to install Rails, all because I failed to add that line to my bashrc file before the first attempt. You can read all about RubyGems setup here.

Third, install Rails with ‘gem install rails’. This will install an account local copy of Rails under ~/.gem, specifically ~/.gem/ruby/2.3.0/gems with this version of Gems. Installing a local account copy is no different than what happens with Node.js installations. There’s always a debate about local vs global installation; due to security and my personal paranoia I always prefer local (non-root) account installation to minimize any unintended consequences a global installation might engender.

Fourth, to be able to reach the Ruby instance outside the Raspberry Pi, I modified the file ~/[project]/config/boot.rb and added the following lines of code at the end of the file:

require 'rails/commands/server'module Railsclass Serverdef default_optionssuper.merge({Port: 8081, Host: '0.0.0.0'})endendend

The merge binds the web server to whatever IP address DNS assigns to the Raspberry Pi (‘0.0.0.0’) instead of using localhost as the defult, and changes the port from the default of 3000 to 8081.

Finally, and this is just extra, I made a tiny modification to the default index file at ~/.gem/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/templates/rails/welcome/index.html.erb to add the text “Raspberry Pi 3” in order to drive home that the default web page was in fact coming from the Raspberry Pi 3.

Now on to doing something more useful…

all creatures small and smaller

It’s been a while since I lead off with any of the household animals, especially the Labs. I can still call out plural Labs because Annie is a Labradoodle mix. Pride of place in this photo belongs to Ruby, who has perfected the side-long look like no other Lab that’s ever lived with us. She loves to hop up on the sofa next to me, sidle over close, and then give me that “come hither” look, which for a Lab means “walk hither.” Annie, back in the shadows, is watching, picking up tips. Her schtick are her flying leaps, which I’m assuming come from the Poodle side of the Doodle mix.

The Mackerel Tabbies seem to be getting along pretty well these days, at least in the big cat tree. I’ve not checked in about a month, but back in April, at six months, the Gingersnaps were weighed at nine pounds each. Lulu, resting at the bottom, is a little over fourteen. Everybody realizes Lulu is our special needs cat, and they give her reasonable wide berth. But when it comes time to nap, everybody gets along in the cat tree. As long as nobody but Lulu goes in the cat condo.

Gear

I’m photographing more, but posting less. The breaks are good as long as the don’t become indefinite. Top photo was taken with the Olympus E-M10 and the 14-42 EZ pancake zoom, bottom with the E-M10 and 45mm Zuiko. I also took the luxury of post processing with Lightroom 6.