GIG

赴くままに技術を。

Rdenvを使ってrubyをインストール

開発環境を作るときの問題点

Rdenvインストール

インストール後に気づきましたが、riywo/anyenv · GitHubを利用した方が.bash_profileでの記述等を鑑みて、良かったと後悔...。

入れたもののサマリをしたの表にまとめておく。

パッケージ名 URL 説明
rdenv https://github.com/sstephenson/rbenv rdenvの本体
ruby-build https://github.com/sstephenson/ruby-build.git rdenvでinstallコマンドを使うためのプラグイン
  • rdenvのインストール

git cloneするときにgit://だと名前解決できないよと怒られた。 間違いなく自分のPCに原因あるな...。

   $ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
   $ echo 'export PATH="$PATH:$HOME/.rbenv/bin"' >> ~/.bashrc
   $ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
   $ source ~/.bashrc
  • ruby-buildのインストール
   $ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/rucby-build

Rubyのインストール

   $ rbenv install -l
   .. インストールするバージョンを選択
   $ rvbenv install 2.1.0-rc1
   .. 結構長いので放置して帰宅
   $ rbenv rehash
   $ rbenv global 2.1.0-rc1

インストールできたか確認

  $ which ruby
     /cygdrive/c/Users/Owner/.rbenv/shims/ruby
   $ ruby -v
     ruby 2.1.0dev (2013-12-20 trunk 44301) [i386-cygwin]
   $ gem -v
     2.2.0.rc.1

anyenvを利用する

あとから見てやっぱりこっちを入れておけばよかったと後悔。。 以下のものが利用可能

上記と同じことをしてみる。

    $ git clone https://github.com/riywo/anyenv ~/.anyenv
    $ echo 'export PATH="$HOME/.anyenv/bin:$PATH"' >> ~/.bashrc
    $ echo 'eval "$(anyenv init -)"' >> ~/.bashrc
    $ exec $SHELL -l

rdenvをインストールする

$ anyenv install rdenv
$ exec $SHELL -l

あとは同じ

$ rdenv install (ほしいrubyのバージョン)

[トラブルシューティング] "checking whether the C compiler works... no"

rdenv install中に以下のようなエラーが出た。

checking whether the C compiler works... no
configure: error: in `/tmp/ruby-build.20140217161432.7816/yaml-0.1.5':
configure: error: C compiler cannot create executables
See `config.log' for more details

指示に従って、/tmp/ruby-build.XXXXXXXXXXXXXXX.XXXX/yaml-0.1.5/config.logを見てみたけど、 さっぱり。

gcc: error: unrecognized command line option '-V'
gcc: fatal error: no input files
compilation terminated.
configure:3098: $? = 1
configure:3087: gcc -qversion >&5
gcc: error: unrecognized command line option '-qversion'
gcc: fatal error: no input files
compilation terminated.
configure:3098: $? = 1
configure:3118: checking whether the C compiler works
configure:3140: gcc  -I/cygdrive/c/Users/Owner/.rbenv/versions/2.1.0-rc1/include  -L/cygdrive/c/Users/Owner/.rbenv/versions/2.1.0-rc1/lib  conftest.c  >&5
/usr/lib/gcc/i686-pc-cygwin/4.8.2/cc1.exe: error while loading shared libraries: cygmpc-3.dll: cannot open shared object file: No such file or directory
configure:3144: $? = 1
configure:3182: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "yaml"
| #define PACKAGE_TARNAME "yaml"
| #define PACKAGE_VERSION "0.1.5"
| #define PACKAGE_STRING "yaml 0.1.5"
| #define PACKAGE_BUGREPORT "http://pyyaml.org/newticket?component=libyaml"
| #define PACKAGE_URL ""
| #define PACKAGE "yaml"
| #define VERSION "0.1.5"
| #define YAML_VERSION_MAJOR 0
| #define YAML_VERSION_MINOR 1
| #define YAML_VERSION_PATCH 5
| #define YAML_VERSION_STRING "0.1.5"
| /* end confdefs.h.  */
|
| int
| main ()
| {
|
|   ;
|   return 0;
| }
configure:3187: error: in `/tmp/ruby-build.20140217185557.8052/yaml-0.1.5':
configure:3189: error: C compiler cannot create executables

gccがちゃんとインストールされていないかも。。と思い、再インストールしたら今度はうまくインストールできた。

$ apt-cyg remove gcc-core
$ apt-cyg install gcc-core