Help us understand the problem. What is going on with this article?

Raspberry PiにRuby (2.4.1)インストール

More than 3 years have passed since last update.

Raspberry Piに最新安定版(2017/5/17)のRuby (2.4.1)をインストールする。

rbenvのインストール

1. gitインストール

user@raspberrypi:~ $ sudo apt-get install git
Reading package lists... Done
Building dependency tree
Reading state information... Done
git is already the newest version.
git set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 20 not upgraded.

2. rbenvインストール

user@raspberrypi:~ $  git clone https://github.com/rbenv/rbenv.git ~/.rbenv
Cloning into '/home/user/.rbenv'...
remote: Counting objects: 2595, done.
remote: Total 2595 (delta 0), reused 0 (delta 0), pack-reused 2595
Receiving objects: 100% (2595/2595), 476.26 KiB | 184.00 KiB/s, done.
Resolving deltas: 100% (1627/1627), done.
Checking connectivity... done.

3. .rbenvのsrcでコンパイル

user@raspberrypi:~ $ cd ~/.rbenv && src/configure && make -C src
make: Entering directory '/home/user/.rbenv/src'
gcc -fPIC     -c -o realpath.o realpath.c
gcc -shared -Wl,-soname,../libexec/rbenv-realpath.dylib  -o ../libexec/rbenv-realpath.dylib realpath.o
make: Leaving directory '/home/user/.rbenv/src'

4. .bashrcにPATH通す

user@raspberrypi:~ $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
#### 5. rbenvの初期化&rbenvコマンド化
user@raspberrypi:~ $ ~/.rbenv/bin/rbenv init
# Load rbenv automatically by appending
# the following to ~/.bashrc:

eval "$(rbenv init -)"


user@raspberrypi:~ $ source ~/.bashrc

6. rbenvインストール確認

user@raspberrypi:~ $ rbenv -v
rbenv 1.1.0-2-g4f8925a

*rbenv update時は$ cd .rbenv/ & $ git pull

7. Rubyをインストールするための rbenvプラグインであるrube-build(rubyのコンパイルとインストールを行う)をインストール

user@raspberrypi:~ $ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
Cloning into '/home/user/.rbenv/plugins/ruby-build'...
remote: Counting objects: 7534, done.
remote: Compressing objects: 100% (48/48), done.
remote: Total 7534 (delta 36), reused 0 (delta 0), pack-reused 7483
Receiving objects: 100% (7534/7534), 1.54 MiB | 330.00 KiB/s, done.
Resolving deltas: 100% (4567/4567), done.
Checking connectivity... done.

8. rbenvでインストール可能なrubyのversionを調べる (2.4.1が最新)

user@raspberrypi:~/.rbenv $ rbenv install -l

9. rbenv経由でrubyインストール(20minぐらいかかる)

user@raspberrypi:~/.rbenv $ rbenv install 2.4.1
Downloading ruby-2.4.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.1.tar.bz2
Installing ruby-2.4.1...
Installed ruby-2.4.1 to /home/user/.rbenv/versions/2.4.1

10. rubyのversion変更&rubyのインストール確認

まずは元のrubyのversion確認

user@raspberrypi:~/.rbenv $ ruby -v
ruby 2.1.5p273 (2014-11-13) [arm-linux-gnueabihf]

rubyのversion変更
(ここでrbenvによるversion変更に失敗した場合は、.bashrcを確認して
export PATH="$HOME/.rbenv/bin:$PATH", eval "$(rbenv init -)"がきちんと記載されているか確認する)

user@raspberrypi:~ $ rbenv global 2.4.1
user@raspberrypi:~ $ ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [armv7l-linux-eabihf]

(11. bundler入れる)

bundlerを入れるとgemfileの依存関係を解決してくれるのでぜひ入れておく

$ gem install bundler

以下参考
http://qiita.com/hisonl/items/162f70e612e8e96dba50

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away