rbenv

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

このサイトについて

rbenvの日本語リファレンスです。 rbenvの本家サイト(英文) の内容を翻訳して作成していますが、誤訳や誤記があると思いますのでその点についてはご了承ください。 もし、誤訳などの間違いを見つけましたら、 @tomof まで教えていただければ幸いです。

rbenvを使用して、アプリケーションのRuby環境を整えましょう

rbenvは、Rubyのバージョンを選択し、開発(development)環境を製品(production)環境にマッチしていることを保証するために使用します。 rbenvはBundlerによるデプロイ環境を、 Rubyのアップグレードによって損うことなく動作します。

開発環境を強力に。
単一のファイル内に、アプリケーションのRubyのバージョンを指定します。 同じチームの仲間全員で、それを共有してください。 Rubyの異なるバージョン上で、アプリケーションが実行されてしまう問題から解放されます。 Powのようなアプリケーションサービスと合わせて、 コマンドラインから動かすだけです。 環境変数を設定するだけで、Rubyのバージョンの上書きをすることが出来ます。

製品(production)環境を堅実に
アプリケーションの実行ファイルは、オプションを使用したインターフェースになります。 rbenvとBundler binstubsを使用することで、 cronジョブまたはChefレシピ内で、正しい実行環境(runtime)を選択していることを確定するために、 改めてcdコマンドを使用する必要が無くなるでしょう。 Rubyのバージョンは1つの場所、すなわちアプリケーションに依存するため、 バージョンを切り替える時でさえ、アップグレードとロールバックがアトミック(ひとまとまり、1つのものとして)になります。

各プログラムが一つのことを上手くやるようにせよ。(訳注: One thing well. - UNIX哲学の一節だと思われます)
rbenvは、単独でRubyのバージョンを切り替えることに重点を置いています。 これは、シンプルで予測しやすいものになります。 豊富なプラグインによるエコシステムが、あなたのニーズに合わせた調整を可能にしてくれます。 このプロセスを自動化するために、独自のRubyのバージョンのコンパイル、またはruby-buildを使用してください。 rbenv-varsを使用して、 アプリケーション毎に環境変数を指定してください。 プラグインの詳細については、wikiを参照してください。

何故、RVMではなくrbenvを選択するのか?

ガイド

コマンドリファレンス

rbenvコマンドはgitのように、第1引数を基にしたサブコマンドに処理を委任します。 頻繁に使用されるコマンドは下記の通りです。

バージョン履歴

0.4.0 (January 4, 2013)

  • rbenv now prefers .ruby-version files to .rbenv-version files for specifying local application-specific versions. The .ruby-version file has the same format as .rbenv-version but is compatible with other Ruby version managers.
  • Deprecated ruby-local-exec and moved its functionality into the standard ruby shim. See the ruby-local-exec wiki page for upgrade instructions.
  • Modified shims to include the full path to rbenv so that they can be invoked without having rbenv's bin directory in the $PATH.
  • Sped up rbenv init by avoiding rbenv reinitialization and by using a simpler indexing approach. (Users of chef-rbenv should upgrade to the latest version to fix a compatibility issue.)
  • Reworked rbenv help so that usage and documentation is stored as a comment in each subcommand, enabling plugin commands to hook into the help system.
  • Added support for full completion of the command line, not just the first argument.
  • Updated installation instructions for Zsh and Ubuntu users.
  • Fixed rbenv which and rbenv prefix with system Ruby versions.
  • Changed rbenv exec to avoid prepending the system Ruby location to $PATH to fix issues running system Ruby commands that invoke other commands.
  • Changed rbenv rehash to ensure it exits with a 0 status code under normal operation, and to ensure outdated shims are removed first when rehashing.
  • Modified rbenv rehash to run hash -r afterwards, when shell integration is enabled, to ensure the shell's command cache is cleared.
  • Removed use of the += operator to support older versions of Bash.
  • Adjusted non-bare rbenv versions output to include system, if present.
  • Improved documentation for installing and uninstalling Ruby versions.
  • Fixed rbenv versions not to display a warning if the currently specified version doesn't exist.
  • Fixed an instance of local variable leakage in the rbenv shell function wrapper.
  • Changed rbenv shell to ensure it exits with a non-zero status on failure.
  • Added rbenv --version for printing the current version of rbenv.
  • Added /usr/lib/rbenv/hooks to the plugin hook search path.
  • Fixed rbenv which to account for path entries with spaces.
  • Changed rbenv init to accept option arguments in any order.

0.3.0 (December 25, 2011)

  • Added an rbenv root command which prints the value of $RBENV_ROOT, or the default root directory if it's unset.
  • Clarified Zsh installation instructions in the Readme.
  • Removed some redundant code in rbenv rehash.
  • Fixed an issue with calling readlink for paths with spaces.
  • Changed Zsh initialization code to install completion hooks only for interactive shells.
  • Added preliminary support for ksh.
  • rbenv rehash creates or removes shims only when necessary instead of removing and re-creating all shims on each invocation.
  • Fixed that RBENV_DIR, when specified, would be incorrectly expanded to its parent directory.
  • Removed the deprecated set-default and set-local commands.
  • Added a --no-rehash option to rbenv init for skipping the automatic rehash when opening a new shell.

0.2.1 (October 1, 2011)

  • Changed the rbenv command to ensure that RBENV_DIR is always an absolute path. This fixes an issue where Ruby scripts using the ruby-local-exec wrapper would go into an infinite loop when invoked with a relative path from the command line.

0.2.0 (September 28, 2011)

  • Renamed rbenv set-default to rbenv global and rbenv set-local to rbenv local. The set- commands are deprecated and will be removed in the next major release.
  • rbenv now uses greadlink on Solaris.
  • Added a ruby-local-exec command which can be used in shebangs in place of #!/usr/bin/env ruby to properly set the project-specific Ruby version regardless of current working directory.
  • Fixed an issue with rbenv rehash when no binaries are present.
  • Added support for rbenv-sh-* commands, which run inside the current shell instead of in a child process.
  • Added an rbenv shell command for conveniently setting the $RBENV_VERSION environment variable.
  • Added support for storing rbenv versions and shims in directories other than ~/.rbenv with the $RBENV_ROOT environment variable.
  • Added support for debugging rbenv via set -x when the $RBENV_DEBUG environment variable is set.
  • Refactored the autocompletion system so that completions are now built-in to each command and shared between bash and Zsh.
  • Added support for plugin bundles in ~/.rbenv/plugins as documented in issue #102.
  • Added /usr/local/etc/rbenv.d to the list of directories searched for rbenv hooks.
  • Added support for an $RBENV_DIR environment variable which defaults to the current working directory for specifying where rbenv searches for local version files.

0.1.2 (August 16, 2011)

  • Fixed rbenv to be more resilient against nonexistent entries in $PATH.
  • Made the rbenv rehash command operate atomically.
  • Modified the rbenv init script to automatically run rbenv rehash so that shims are recreated whenever a new shell is opened.
  • Added initial support for Zsh autocompletion.
  • Removed the dependency on egrep for reading version files.

0.1.1 (August 14, 2011)

  • Fixed a syntax error in the rbenv help command.
  • Removed -e from the shebang in favor of set -e at the top of each file for compatibility with operating systems that do not support more than one argument in the shebang.

0.1.0 (August 11, 2011)

  • Initial public release.

ライセンス

(The MIT license)

Copyright (c) 2013 Sam Stephenson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 Back to top

© 2010 - 2017 STUDIO KINGDOM