Skip to content

Instantly share code, notes, and snippets.

@masutaka
Last active February 18, 2024 13:32
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masutaka/aad55902efc9214bf857 to your computer and use it in GitHub Desktop.
Save masutaka/aad55902efc9214bf857 to your computer and use it in GitHub Desktop.
【決定版】rbenv を使った ruby のインストール

rbenv および Ruby-2.5.0 のクリーンインストール

  1. Homebrew の rbenv や ruby-build をインストールしていたら、もろもろ削除する

    $ brew uninstall --force rbenv ruby-build
    $ rm -rf ~/.rbenv
    
  2. rbenv をインストールする

    $ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
    
  3. ~/.zshenv に以下を追加し、zsh のシェルを開き直す

    export PATH=$HOME/.rbenv/bin:$PATH
    eval "$(rbenv init -)"
    
  4. rbenv プラグインをインストールする

    $ mkdir -p "$(rbenv root)/plugins"
    
    $ git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)/plugins/ruby-build"
    
    # rbenv install 後に ~/.rbenv/default-gems に記載の gem をインストールしてくれる。
    $ git clone https://github.com/rbenv/rbenv-default-gems.git "$(rbenv root)/plugins/rbenv-default-gems"
    $ echo bundler > "$(rbenv root)/default-gems"
    
    # $ rbenv update すると、~/.rbenv/plugins 以下を全部 git pull してくれる。ruby-build も対象となる。
    $ git clone https://github.com/rkh/rbenv-update.git "$(rbenv root)/plugins/rbenv-update"
    
  5. Ruby-2.5.0 をインストールする。bundler もインストールされる

    # irb や pry を使った時 ↑↓ 等で履歴を辿れるようになる
    $ brew install readline
    
    $ RUBY_CONFIGURE_OPTS="--with-readline-dir=$(brew --prefix readline)" rbenv install -v 2.5.0 && rbenv global 2.5.0 && rehash
    

Ruby がバージョンアップしたら(例: Ruby-2.5.1)

  1. rbenv とプラグインのアップデート

    $ rbenv update
    
  2. Ruby 2.5.1 へのアップデート

    $ RUBY_CONFIGURE_OPTS="--with-readline-dir=$(brew --prefix readline)" rbenv install -v 2.5.1 && rbenv global 2.5.1 && rehash
    
@DoctorofTheEARTH
Copy link

恐れ入ります。
初めて、Rubyをインストールするのですが、Progateの示す手順通りに進めていたところ、インストールできませんでした。原因がわかりません。
どうすればいいか教えて頂けますか? 
rbenv install 2.5.0

ruby-build: use openssl from homebrew
Downloading ruby-2.5.0.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.0.tar.bz2
Installing ruby-2.5.0...

BUILD FAILED (OS X 10.14.5 using ruby-build 20190423)

Inspect or clean up the working tree at /var/folders/ss/t826qgw50bg9_k1vdfq1q2940000gn/T/ruby-build.20190802011204.22835
Results logged to /var/folders/ss/t826qgw50bg9_k1vdfq1q2940000gn/T/ruby-build.20190802011204.22835.log

Last 10 log lines:
tool/config.guess already exists
tool/config.sub already exists
checking build system type... x86_64-apple-darwin18.6.0
checking host system type... x86_64-apple-darwin18.6.0
checking target system type... x86_64-apple-darwin18.6.0
checking whether the C compiler works... no
configure: error: in /var/folders/ss/t826qgw50bg9_k1vdfq1q2940000gn/T/ruby-build.20190802011204.22835/ruby-2.5.0': configure: error: C compiler cannot create executables See config.log' for more details
make: *** No targets specified and no makefile found. Stop.

@masutaka
Copy link
Author

masutaka commented Aug 2, 2019

checking whether the C compiler works... no

なので、コンパイラがありませんね。

macOS なら Apple が提供している Command Line Tools をインストールしましょう。やり方はググってみて下さい。

@DoctorofTheEARTH
Copy link

ありがとうございます

@goodroot
Copy link

ありがとうございました! 🇨🇦 🇯🇵

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment