Setting up a Rails Dev Environment on Raspberry Pi 3

The problem:

I needed to create a Rails dev environment on Raspberry Pi 3, and utilize specific versions of Ruby (2.3.3) and Rails (4.2.1). The following instructions have been verified with a Raspberry Pi running the version of Ubuntu MATE 16.04 designed for the Pi.

  • Step 1: Create a project directory. cd ~ mkdir www

  • Step 2: Install necessary libraries

sudo apt-get update
sudo apt-get install git git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs imagemagick
  • Step 3: Install rbenv
git clone ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
  • Step 4: Install Ruby
rbenv install 2.3.3
rbenv global 2.3.3
rbenv rehash
ruby -v
  • Step 5: Install Rails
gem install bundler
gem install rails -v 4.2.1 --no-document
rbenv rehash
rails -v
  • Step 6: Set Up PostgreSQL
sudo sh -c "echo 'deb xenial-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-common
sudo apt-get install postgresql-9.5 libpq-dev
sudo -u postgres psql
create role  with createdb login password 'password';

Fill in and with your actual credentials. username should match the Ubuntu login you created for your Raspberry Pi.

  • Step 7: Create a rails app
cd ~/www
rails new testapp -d postgresql
cd testapp
  • Step 8: Edit the database config, create the database, & start the app

Open up and modify the config/database.yml file to specify the username you created, adding the following lines under “development”:


Then Create the database and start the app.

bundle exec rake db:create
rails s 

In the included Firefox browser, visit http://localhost:3000, and you should see your new Rails app!