LoginSignup
4
3

More than 5 years have passed since last update.

[Ruby] rbenv install

Posted at

環境

Mac OS Mojava 10.14.3

rbenv install

一旦不要になったバージョンを削除

$ rbenv versions
scripts $ rbenv versions
  system
  * 2.5.1 (set by /Users/harigaik/.rbenv/version)

$ rbenv uninstall -f 2.5.1
$ rbenv rehash

rbenv install

Homebrew でもインストール可能であるが、最新版であれば、clone で更新(とりあえず、そっちでやってみる)

$ brew install rbenv

# or 

$ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
$ mkdir -p ~/.rbenv/plugins
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

.bash_profile 設定

$ vim ~/.bash_profile
# 以下を最後の行に追加
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

$ source ~/.bash_profile

関連パッケージインストール & Ruby インストール

関連パッケージインストール

$ brew install openssl
$ brew install readline
$ brew install libiconv
$ brew install libxml2

インストール可能な Ruby バージョンをチェック

$ rbenv install -l

readline, openssl, iconv のパス指定で Ruby install(2.5.1)

$ RUBY_CONFIGURE_OPTS="--with-readline-dir=$(brew --prefix readline) --with-openssl-dir=$(brew --prefix openssl) --with-iconv-dir=$(brew --prefix libiconv) --with-xml2-include=$(brew --prefix libxml2)/include/libxml2" rbenv install 2.5.1

$ rbenv rehash

# インストールした Ruby のバージョンのリストを確認 
$ rbenv versions
* system (set by /Users/harigaik/.rbenv/version)
  2.5.1

# インストールした Ruby を有効にする
$ rbenv global 2.5.1
  system
  * 2.5.1 (set by /Users/harigaik/.rbenv/version)

SSL証明書のインポート

$ ruby -ropenssl -e "p OpenSSL::X509::DEFAULT_CERT_FILE"

$ sudo curl "https://curl.haxx.se/ca/cacert.pem" -o /usr/local/etc/openssl/cert.pem

Bundlerのインストール

GEMでRuby環境にbundlerのみをインストールする

$ rbenv exec gem install bundler
$ rbenv rehash

# bundler の確認
$ rbenv exec gem list
$ rbenv exec gem which bundler

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

$ cat << EOS > Gemfile
source "http://rubygems.org"
gem "rails", "5.1.6"
EOS

$ bundle install --path vendor/bundle

# rails を確認
$ bundle list

# railsでプロジェクト(今回の例では”example”)を作成
# vendor/bundle に入ったgemを使ってコマンドを実行したい場合は上記のように bundle exec 〜 のようにする
# --skip-bundle の指定を忘れないように!そうでないと bundle install が発動し、Ruby環境にgemがインストールされてしまう!
$ bundle exec rails new example --skip-bundle

# railsをローカルインストールするために使ったbundlerの環境と、ローカルのrailsを削除
$ rm -f Gemfile
$ rm -f Gemfile.lock
$ rm -rf .bundle
$ rm -rvf vendor/bundle
$ rm -rvf vendor

Railsプロジェクトの環境セットアップ

$ cd example
$ bundle install --path vendor/bundle
-> エラーの場合は「bundle install エラー対応」を参照

# .gitignore に追加
$ echo '/vendor/bundle' >> .gitignore

bundle install エラー対応

bundler 2.0.1 問題(1.16.1 にダウングレード)

can't find gem bundler (>= 0.a) with executable bundle 対応

$ cat Gemfile.lock
・
BUNDLED WITH
   1.16.6

$ gem install bundler -v 1.16.1
$ gem uninstall bundler -v 2.0.1

Nokogiri インストールできない問題

macOS SierraでNokogiriがインストールできない問題の解決方法
-> 推奨設定を実施

$ brew install libxml2
$ bundle config build.nokogiri --use-system-libraries --with-xml2-include=$(brew --prefix libxml2)/include/libxml2

Railse server 起動

$ bundle exec rails server

資料

4
3
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
4
3