技術者になりたい何か

技術者になりたい何かの覚書的な何かです

rbenvとruby-buildでさいしんのruby環境を

rbenvとは

rubyのバージョン管理ツール。

複数バージョンのrubyを使いたいとき、リポジトリにないバージョンを使いたい時などに重宝する。

 

rbenvのインストール

Debianの場合実はリポジトリにある。

$ sudo apt-get install rbenv

 
ruby-buildのインストール。


ruby-buildは任意のバージョンのrubyをDLしてきてインスコしてくれるツール。
gitでもってきて.rbenv/plugin以下に配置

$ mkdir -p ~/.rbenv/plugins
$ cd ~/.rbenv/plugins
~/.rbenv/plugins $ git clone git://github.com/sstephenson/ruby-build.git
Cloning into 'ruby-build'...
remote: Reusing existing pack: 3312, done.
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 3318 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3318/3318), 560.20 KiB | 430.00 KiB/s, done.
Resolving deltas: 100% (1569/1569), done.
Checking connectivity... done.

 
bssh_profilesにパス追記。

$ emacs .bash_profile
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

 
つかいかた

 

$ rbenv help
Usage: rbenv <command> [<args>]

Some useful rbenv commands are:
   commands    List all available rbenv commands
   local       Set or show the local application-specific Ruby version
   global      Set or show the global Ruby version
   shell       Set or show the shell-specific Ruby version
   install     Install a Ruby version using ruby-build
   uninstall   Uninstall a specific Ruby version
   rehash      Rehash rbenv shims (run this after installing executables)
   version     Show the current Ruby version and its origin
   versions    List all Ruby versions available to rbenv
   which       Display the full path to an executable
   whence      List all Ruby versions that contain the given executable

See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/sstephenson/rbenv#readme

 

install --listでインストール可能なrubyのバージョンを確認。

$ rbenv install --list
Available versions:
  1.8.5-p113
  1.8.5-p114
 
  ~~省略~~

  2.2.3
  2.3.0
  2.3.1
  ~~省略~~


インストール。これは2.4.0。

$ rbenv install 2.4.0

 
システムデフォルトのrubyのバージョンを2.4.0に。

$ rbenv global 2.4.0

 
今いるディレクトリで使用するruby のバージョンを2.4.0に

$ rbenv local 2.4.0

 

versionsでrbenv経由で入れてるrubyのバージョン一覧表示

 

$ rbenv versions
  system
  2.1.7
  2.2.3
  2.3.0
  2.3.1
* 2.4.0 (set by /home/tmin/.rbenv/version)

 

rehashで環境再設定?新しくruby入れたときとか設定変えたときとかにやる

$ rbenv rehash

けどぶっちゃけこれが何をやっているのかよくわからない・・・

バージョン確認。

$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]

 


mikutterを動かす。


mikutterが置いてあるディレクトリに移動してbundleで依存ライブラリ関係を入れる。

~/mikutter$ bundle update
rbenv: bundle: command not found

 
あれ?bundleが入ってないらしい

~/mikutter$ gem install bundler
Fetching: bundler-1.14.3.gem (100%)
Bundler and RubyGems.org are free for anyone to use, but maintaining them costs more than $25,000 USD every month. Help us cover those costs so that we can keep the gem ecosystem free for everyone: https://ruby.to/support-bundler
Successfully installed bundler-1.14.3
Parsing documentation for bundler-1.14.3
Installing ri documentation for bundler-1.14.3
Done installing documentation for bundler after 14 seconds
1 gem installed

 


おk。改めて

~/mikutter$ bundle install --path vender/bundle
Fetching gem metadata from https://rubygems.org/.............
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies...
Installing rake 10.5.0
Installing public_suffix 2.0.5
Installing pkg-config 1.1.7
Installing safe_yaml 1.0.4
Installing delayer 0.0.2
Installing locale 2.1.2
Installing text 1.3.1
Installing hashdiff 0.3.2
Installing httpclient 2.8.3
Installing instance_storage 1.0.0
Installing json_pure 1.8.6
Installing memoist 0.15.0
Installing metaclass 0.0.4
Installing mini_portile2 2.1.0
Installing moneta 0.8.1
Installing oauth 0.5.1
Installing power_assert 1.0.1
Installing ruby-hmac 0.4.0
Installing ruby-prof 0.16.2 with native extensions
Installing totoridipjp 0.1.0
Installing unf_ext 0.0.7.2 with native extensions
(中略

nstalling gdk_pixbuf2 3.1.1
Installing gtk2 3.1.1 with native extensions
Bundle complete! 22 Gemfile dependencies, 43 gems now installed.
Bundled gems are installed into ./vender/bundle.

 問題なければBundle complete!まで出るはず。

Errorが出たときは何かしらのライブラリパッケージが足りない時が多い。

libなんちゃらとか、libなんちゃらdevってパッケージ入れると解決したりしなかったり。

 

$ ruby mikutter.rb

 


で動けばおk。


redmineとか動かすときにリポジトリ配布のrubyのバージョンが合わないときとかに使うと幸せになれる。
あと、いくつかのrailsプロジェクトとか動かしたいときに、rbenv localで各ディレクトリで使うrubyのバージョンを指定しとくと使い分けられたりします。

Sponsored Link