Eyes, JAPAN Blog > How to switch to rbenv. Part 1.

How to switch to rbenv. Part 1.

denvazh

この記事は1年以上前に書かれたもので、内容が古い可能性がありますのでご注意ください。

Why?

rvm is a great tool and definetly worth using when one need to have completely “clean” list of installed gems for specific ruby and ability to switch between ruby and gems on the fly. Unfortunately, it is less usable and requires more effort to set it up for production environment. Especially, if production environment doesn’t rely on bash/zsh shells. Alternative to what rvm tries to do is rbenv – lightweight tool to deal with different ruby versions. Combined with the other one for managing gems – Bundler – we get pretty much similar setup to what we would usually have with rvm and its gemset. In this very nice blog post I will show how to install rbenv on the Mac environment with homebrew.

Action

Warning: rvm and rbenv is not compatible, thus if you’d like to use rbenv you have to uninstall rvm and install rbenv afterwards.

Uninstalling rvm

After rvm was successfully uninstalled, please close terminal and re-open it again.

	[~]$: rvm implode
	Are you SURE you wish for rvm to implode?
	This will recursively remove /Users/denvazh/.rvm and other rvm traces?
	(anything other than 'yes' will cancel) > yes
	Removing rvm-shipped binaries (rvm-prompt, rvm, rvm-sudo rvm-shell and rvm-auto-ruby)
	Removing rvm wrappers in /Users/denvazh/.rvm/bin
	Hai! Removing /Users/denvazh/.rvm
	/Users/denvazh/.rvm has been removed.

	Note you may need to manually remove /etc/rvmrc and ~/.rvmrc if they exist still.
	Please check all .bashrc .bash_profile .profile and .zshrc for RVM source lines and delete or comment out if this was a Per-User installation.
	Also make sure to remove `rvm` group if this was a system installation.
	Finally it might help to relogin / restart if you want to have fresh environment (like for installing RVM again).

Checking if homebrew has correct PATH settings

Make sure that contents of the /etc/paths is as follows:

	/usr/local/bin
	/usr/bin
	/bin
	/usr/local/sbin
	/usr/sbin
	/sbin

Installing rbenv and ruby-build

	[~]$: brew install rbenv ruby-build

Using system-wide install

	[~]$: echo "export RBENV_ROOT=/usr/local/var/rbenv" >> ~/.bashrc
	[~]$: echo "if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi" >> ~/.bashrc

Installing ruby

	[~]$: rbenv install 2.0.0-p247
	[~]$: rbenv global 2.0.0-p247
	[~]$: ruby -v
	ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.3.0]

Configuring rbenv for specific system

Install plugin to manage environment variables for rbenv and bundler gem available with rbenv

	[~]$: brew install rbenv-vars
	[~]$: echo "GEM_PATH=.bundle" >> /usr/local/var/rbenv/vars
	[~]$: gem install bundler && rbenv rehash

Setting up bundler to have closer to gemset experience

	[~]$: bundle config --global bin bin
	[~]$: bundle config --global path .bundle

This is necessary to simply type less :). Because bundler installs all gems to .bundle directory below your project working directory, for every call executable scripts, that comes with given gem, one always has to use bundle exec %gemname% %arguments%. With change like above, bundle will create links for executables in bin directory. For example to show all rake tasks for rails project, it would be enough to run:

	[~]$: ./bin/rake -T

Conclusion

I will explain Why I prefer rbenv? in details in the next blog post (and obviously it will have a part 2 in its title). There are at least two major benefits for using rbenv:

  • for rails development is is ability to install and rely on gems installed automatically by Bundler
  • for custom production environment it is not necessary to change/move to bash/zsh for the root user

Update

For the Part 2 for this topic, please follow here

  • このエントリーをはてなブックマークに追加

Comments are closed.