LoginSignup
7
8

More than 5 years have passed since last update.

Raspberry Pi 1 Model B にRails環境を構築するには

Last updated at Posted at 2016-03-06

前提

この記事は下記の環境に、Railsの実行環境を構築する方法を記載しています。

  • Raspberry Pi 1 Model B (Mem:512MB)
  • libssl-dev,libreadline-dev,libsqlite3-devをインストール済み(なければ->sudo apt-get install libssl-dev libreadline-dev)

現状の確認

私の環境は下記のようなバージョンでした。

…中略…
Linux raspberrypi 4.1.13+ #826 PREEMPT Fri Nov 13 20:13:22 GMT 2015 armv6l
…中略…
pi@raspberrypi ~ $ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [arm-linux-eabihf]
pi@raspberrypi ~ $ git --version
git version 1.7.10.4

rbenvのインストール

rbenvをインストールします。.bashrcで読み込むように設定していますが.bash_profileがいい人は、適宜読み替えてください。

pi@raspberrypi ~ $ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
Cloning into '/home/pi/.rbenv'...
remote: Counting objects: 2495, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 2495 (delta 1), reused 0 (delta 0), pack-reused 2488
Receiving objects: 100% (2495/2495), 454.52 KiB | 297 KiB/s, done.
Resolving deltas: 100% (1569/1569), done.
pi@raspberrypi ~ $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
pi@raspberrypi ~ $ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
pi@raspberrypi ~ $ . .bashrc 
pi@raspberrypi ~ $ rbenv
rbenv 1.0.0-19-g29b4da7
…省略…

ruby-buildのインストール

rbenvの配下にruby-buildをインストールします。

pi@raspberrypi ~ $ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
Cloning into '/home/pi/.rbenv/plugins/ruby-build'...
remote: Counting objects: 5880, done.
remote: Compressing objects: 100% (39/39), done.
remote: Total 5880 (delta 18), reused 0 (delta 0), pack-reused 5836
Receiving objects: 100% (5880/5880), 1.13 MiB | 376 KiB/s, done.
Resolving deltas: 100% (3335/3335), done.

rubyのインストール

rbenvでインストール可能なrubyを確認して、ruby(2.2.4)をインストールします。CPUパワーが無いのですごく時間がかかりますが我慢しましょう。

pi@raspberrypi ~ $ rbenv install -l
Available versions:
  1.8.6-p383
…中略…
  2.2.4
…中略…
pi@raspberrypi ~ $ time rbenv install 2.2.4
Downloading ruby-2.2.4.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.4.tar.bz2
Installing ruby-2.2.4...
Installed ruby-2.2.4 to /home/pi/.rbenv/versions/2.2.4


real    166m15.645s
user    136m45.840s
sys 6m48.320s
…3時間近く時間がかかる…

rubyの切替

pi@raspberrypi ~ $ rbenv versions
* system (set by /home/pi/.rbenv/version)
  2.2.4
pi@raspberrypi ~ $ rbenv global 2.2.4
pi@raspberrypi ~ $ ruby -v
ruby 2.2.4p230 (2015-12-16 revision 53155) [armv6l-linux-eabihf]

これで2.2.4が使えるようになった。

railsのインストールとプロジェクトの作成

project/にexampleプロジェクトを作成するつもりで書いてますので、適宜読み替えてください。
またrailsのバージョンは指定していないので最新版がインストールされますが、バージョンを固定したい場合はGemfileのrails行にバージョンを追記してください。

pi@raspberrypi ~ $ mkdir projects/example && cd $_
pi@raspberrypi ~/projects/example $ 
pi@raspberrypi ~/projects/example $ cat << EOS > Gemfile
source "http://rubygems.org"
gem "rails"
EOS
pi@raspberrypi ~/projects/example $ bundle install --path vendor/bundle
…中略…
pi@raspberrypi ~/projects/example $ bundle exec rails -v
Rails 4.2.5.2
pi@raspberrypi ~/projects/example $ bundle exec rails new . --skip-bundle
…中略…    conflict  Gemfile
Overwrite /home/pi/projects/example/Gemfile? (enter "h" for help) [Ynaqdh] y (←上書きするかたズレられるので、y)
…中略…
pi@raspberrypi ~/projects/example $ bundle install --path vendor/bundle

rails起動

これで準備完了。railsのWEBrickを起動して、開発を始めよう。

pi@raspberrypi ~/projects/example $ bundle exec rails s -b 0.0.0.0
=> Booting WEBrick
=> Rails 4.2.5.2 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-03-06 18:42:02] INFO  WEBrick 1.3.1
[2016-03-06 18:42:02] INFO  ruby 2.2.4 (2015-12-16) [armv6l-linux-eabihf]
[2016-03-06 18:42:02] INFO  WEBrick::HTTPServer#start: pid=27625 port=3000
7
8
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
7
8