rbenv

moving from RVM to rbenv: migration guide.

  1. https://github.com/rbenv/rbenv
  2. http://makandracards.com/makandra/21545-rbenv-how-to-switch-to-another-ruby-version-temporarily-per-project-or-globally

takeaways:

uninstallation of RVM

installation

configuration

source in $ZDOTDIR/.zshrc:

eval "$(rbenv init -)"

usage

  1. http://makandracards.com/makandra/21545

bundler and spring

see bundler and spring for details.

pow

  1. https://github.com/basecamp/pow/wiki/Troubleshooting#rbenv

create ~/.powconfig:

export PATH="~/.rbenv/shims:/usr/local/opt/rbenv/bin:$PATH"

check where bin/ is located - this is /usr/local/opt/rbenv/bin/ if rbenv has been installed with brew.

don’t forget to restart pow (or kill -9 process better).

command-t

switch to system Ruby when compiling command-t Vim plugin in ~/.vim/update_bundles:

puts "compiling command-t..."

# https://langui.sh/2014/03/10/wunused-command-line-argument-hard-error-in-future-is-a-harsh-mistress
environment = 'ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future"'
command_t_path = File.join 'command-t', 'ruby', 'command-t'
rbenv_init_script = 'eval "$(rbenv init -)"'
command_t_build_script = 'rbenv shell system && ruby extconf.rb && make'

puts `zsh -c 'cd #{command_t_path} && #{rbenv_init_script} && #{environment} #{command_t_build_script}'`

if you install Ruby with brew (brew install ruby) it will be used as system Ruby by rbenv and command-t won’t work since it expects its native extensions to be compiled with vim Ruby version (2.0.0p648).

Chef

ChefDK and rbenv

  1. https://dwradcliffe.com/2014/09/19/chefdk-with-rbenv.html
  2. http://unix.stackexchange.com/a/71258

background info:

if you install knife-solo gem, rbenv will create a knife shim - it will always point to executable from this gem and will make knife executable from ChefDK unavailable.

3 ways to solve this problem:

ruby_rbenv cookbook

RVM cannot be installed on Debian 8 with rvm cookbook - installing rbenv with ruby_rbenv cookbook went smoothly.

recipe:

include_recipe 'ruby_build'
include_recipe 'ruby_rbenv::user'

attribute file:

override['rbenv']['user_installs'] = [
  {
    'user' => 'deploy',
    'rubies' => ['2.3.0'],
    'global' => '2.3.0',
    'gems' => {
      '2.3.0' => [
        { 'name' => 'bundler' }
      ]
    }
  }
]

NOTE: bundler gem is not installed by default.

Capistrano

  1. https://github.com/capistrano/rbenv

this gem provides rbenv support for Capistrano: it allows to use rbenv managed Rubies on target machine.

Capfile:

require 'capistrano/rbenv'

config/deploy.rb:

set :rbenv_type, :user
set :rbenv_ruby, File.read('.ruby-version').strip
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins, %w(rake gem bundle ruby rails)
set :rbenv_roles, :all

troubleshooting

shim is not created after gem is installed

to diagnose the problem run rehashing manually (rehashing synchonizes shims with installed gems):

$ rbenv rehash
rbenv: cannot rehash: /Users/tap/.rbenv/shims/.rbenv-shim exists

solution

  1. https://github.com/rbenv/rbenv/issues/759

obviously solution is to remove .rbenv-shim file:

$ rm /Users/tap/.rbenv/shims/.rbenv-shim

/usr/local/Cellar/rbenv/1.1.1/libexec/rbenv: No such file or directory

$ git up
/Users/tap/.rbenv/shims/git-up: line 21: /usr/local/Cellar/rbenv/1.1.1/libexec/rbenv: No such file or directory
$ bundle
/Users/tap/.rbenv/shims/bundle: line 21: /usr/local/Cellar/rbenv/1.1.1/libexec/rbenv: No such file or directory

solution

$ rbenv rehash
rbenv: cannot rehash: /Users/tap/.rbenv/shims/.rbenv-shim exists
$ rm /Users/tap/.rbenv/shims/.rbenv-shim
$ rbenv rehash