LoginSignup
10
9

More than 5 years have passed since last update.

Raspberry Pi で rbenv / Ruby on Rails を動かすまでの個人的メモ

Last updated at Posted at 2015-04-04

PCでのRails開発環境と同じものにしたかったので、rbenvでrubyを入れてrailsを動かしました。
ただ、ビルドに時間がかかるのでおすすめはしません。
※Raspberry pi 2 / Rails 4.2.0 で動作確認

前準備

必要に応じて設定

$ sudo raspi-config

リポジトリのアップデートも忘れずに

$ apt-get update
$ apt-get upgrade

rbenvのインストール

ビルドに時間がかかるので注意。

現在のrubyバージョンを確認

$ pi@raspberrypi ~ $ ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [arm-linux-eabihf]
# OpenSSLのインストール rbenvのインストールに必要
$ apt-get install libssl-dev
$ cd /usr/local
$ git clone git://github.com/sstephenson/rbenv.git rbenv
$ mkdir rbenv/shims rbenv/versions
$ chgrp -R users rbenv
$ chmod -R g+rwxXs rbenv

/etc/profile.d/rbenv.sh を作成して下記の内容を記述

export RBENV_ROOT=/usr/local/rbenv
export PATH="/usr/local/rbenv/shims:/usr/local/rbenv/bin:$PATH"
eval "$(rbenv init -)"

再起動後 rbenv のコマンドが通ることを確認

$ reboot
$ pi@raspberrypi ~ $ rbenv --version
$ rbenv 0.4.0-129-g7e0e85b

ruby-buildも入れる

git clone git://github.com/sstephenson/ruby-build.git ruby-build
ruby-build/install.sh
rbenv rehash

rubyのビルドに必要なのでインストール

$ sudo apt-get install ruby-dev

ビルドします!
※Raspberry Pi 2 で 1時間ほどかかります。Raspberry Pi だと2時間以上かかりました。

$ pi@raspberrypi ~ $ rbenv install 2.2.0
Downloading ruby-2.2.0.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/7671e394abfb5d262fbcd3b27a71bf78737c7e9347fa21c39e58b0bb9c4840fc
Installing ruby-2.2.0...
Installed ruby-2.2.0 to /usr/local/rbenv/versions/2.2.0
$ pi@raspberrypi ~ $ rbenv global 2.2.0 # 2.2.0をglobalに設定
$ pi@raspberrypi ~ $ ruby --version # バージョン確認
$ ruby 2.2.0p0 (2014-12-25 revision 49005) [armv7l-linux-eabihf] # 変更を確認!

Railsのインストール

$ pi@raspberrypi ~ $ gem install rails
Fetching: thread_safe-0.3.4.gem (100%)
Successfully installed thread_safe-0.3.4

・・・

Parsing documentation for rails-4.2.0
Installing ri documentation for rails-4.2.0
Done installing documentation for thread_safe, tzinfo, i18n, activesupport, rails-deprecated_sanitizer, mini_portile, nokogiri, rails-dom-testing, loofah, rails-html-sanitizer, erubis, builder, actionview, rack, rack-test, actionpack, tilt, multi_json, hike, sprockets, sprockets-rails, bundler, thor, railties, globalid, activejob, mime-types, mail, actionmailer, arel, activemodel, activerecord, rails after 5480 seconds
33 gems installed
$ apt-get install libsqlite3-dev
$ bundle install
$ rails s -b 0.0.0.0

サーバーの起動を確認すれば完了!

rbenvのインストール方法 参考:

http://yatmsu.hatenablog.com/entry/20120413/1334300058
http://www.iconoclastlabs.com/blog/ruby-on-rails-on-the-raspberry-pi-b-with-rbenv

10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9