- What is rbenv?
- Check out rbenv into ~/.rbenv
- Add ~/.rbenv/bin to your $PATH for access to the rbenv command-line utility
- Add rbenv init to your shell to enable shims and auto-completion
- Restart your shell as a login shell so the path changes take effect
- Install ruby-build plugin
- Update ruby-build plugin
- Uninstall a specific Ruby version
- Rebuild the shim executables
- rbenv-gemset plugin
- Update rbenv
- DO NOT Install Ruby RDoc and Ruby Index for gems
What is rbenv?
rbenv is a tool for simple Ruby version management.
Use rbenv to pick a Ruby version for your application and guarantee that your development environment matches production. Put rbenv to work with Bundler for painless Ruby upgrades and bulletproof deployments.
Powerful in development. Specify your app's Ruby version once, in a single file. Keep all your teammates on the same page. No headaches running apps on different versions of Ruby. Just Works™ from the command line and with app servers like Pow. Override the Ruby version anytime: just set an environment variable.
Rock-solid in production. Your application's executables are its interface with ops. With rbenv and Bundler binstubs you'll never again need to cd in a cron job or Chef recipe to ensure you've selected the right runtime. The Ruby version dependency lives in one place—your app—so upgrades and rollbacks are atomic, even when you switch versions.
One thing well. rbenv is concerned solely with switching Ruby versions. It's simple and predictable. A rich plugin ecosystem lets you tailor it to suit your needs. Compile your own Ruby versions, or use the ruby-build plugin to automate the process. Specify per-application environment variables with rbenv-vars. See more plugins on the wiki.
- Provide support for specifying application-specific Ruby versions.
- Let you change the global Ruby version on a per-user basis.
- Allow you to override the Ruby version with an environment variable.
In contrast with RVM, rbenv does not…
- Need to be loaded into your shell. Instead, rbenv's shim approach works by adding a directory to your $PATH.
- Override shell commands like cd or require prompt hacks. That's dangerous and error-prone.
- Have a configuration file. There's nothing to configure except which version of Ruby you want to use.
- Install Ruby. You can build and install Ruby yourself, or use ruby-build to automate the process.
- Manage gemsets. Bundler is a better way to manage application dependencies. If you have projects that are not yet using Bundler you can install the rbenv-gemset plugin.
- Require changes to Ruby libraries for compatibility. The simplicity of rbenv means as long as it's in your $PATH, nothing else needs to know about it.
- Prompt you with warnings when you switch to a project. Instead of executing arbitrary code, rbenv reads just the version name from each project. There's nothing to "trust."
This will get you going with the latest version of rbenv and make it easy to fork and contribute any changes back upstream.
Check out rbenv into ~/.rbenv
Add ~/.rbenv/bin to your $PATH for access to the rbenv command-line utility
Ubuntu note: Modify your ~/.profile instead of ~/.bash_profile.
Zsh note: Modify your ~/.zshrc file instead of ~/.bash_profile.
Add rbenv init to your shell to enable shims and auto-completion
Same as in previous step, use ~/.profile on Ubuntu, ~/.zshrc for Zsh.
NOTE: Personally I prefer to use a separate script to set up environment variables rather than modifying ~/bash_profile or ~/.profile. It's more flexible.
Restart your shell as a login shell so the path changes take effect
You can now begin using rbenv.
Install ruby-build plugin
ruby-build plugin provides an rbenv install command that simplifies the process of installing new Ruby versions
Update ruby-build plugin
To update ruby-build after it has been installed, run git pull in your cloned copy of the repository, then re-run the install script.
Install a Ruby version using ruby-build plugin
To compile Ruby from source code, you need to following packages installed on Ubuntu/Debian (amd64/x86_64)
OPTIONAL: libmysql++-dev libsqlite3-dev
Install a Ruby version using ruby-build
NOTE: Ruby versions will be installed into a directory of the same name under ~/.rbenv/versions. To see more when compiling Ruby, use the -v option.
To see a list of all available Ruby versions, run rbenv install --list. You may also tab-complete available Ruby versions if your rbenv installation is properly configured. As an alternative, you can download and compile Ruby yourself into ~/.rbenv/versions/.
Uninstall a specific Ruby version
Rebuild the shim executables
IMPORTANT: You should do this any time you install a new Ruby executable (for example, when installing a new Ruby version, or when installing a gem that provides a command).
Installs shims for all Ruby executables known to rbenv (i.e., ~/.rbenv/versions/*/bin/*). Run this command after you install a new version of Ruby, or install a gem that provides commands.
Recommended: Alternatively, you can install gem rbenv-rehash to avoid rehashing all the time.
zlib is required for gem to work, you'll get the error below when update or install gems if you don't have zlib installed on the system.
IMPORTANT: After installing zlib, rbenv uninstall and rbenv install (re-compile) Ruby versions again to make gem work.
NOTE: libssl-dev will install zlib1g-dev as dependency.
rbenv-gemset is an extension for the rbenv ruby version manager that allows you to use "gemsets", sandboxed collections of gems. This lets you have multiple collections of gems installed in different sandboxes, and specify (on a per-application basis) which sets of gems should be used.
clone rbenv-gemset from GitHub Repository into $HOME/.rbenv/plugins directory
In application directory, create a file named .rbenv-gemsets and put the names of the gemsets wanted in it, separated by whitespace. The first gemset in the list will be the primary gemset, where new gems will be installed.
Now, all commands involving gems will use the gemsets you specified.
The gemset plugin will cause rbenv to search for the .rbenv-gemsets file in the current directory, as well as in all ancestor directories, so as long as there is an .rbenv-gemsets file at or above the current directory.
Alternatively, you can set the RBENV_GEMSET_FILE environment variable to the absolute path of the gemset file.
If you've installed rbenv manually using git, you can upgrade your installation to the cutting-edge version at any time
To use a specific release of rbenv, check out the corresponding tag:
DO NOT Install Ruby RDoc and Ruby Index for gems
If you prefer NOT to install RDoc (Ruby Documentation) and ri (Ruby Index), create $HOME/.gemrc or add in /etc/gemrc with the following contents
This is recommended on server deployment.
Install vagrant or vmc via RubyGems and rbenv rehash, the following error will occur when running vagrant:
libssl-dev is required when installing (compiling Ruby)
For Ubuntu (amd64/x86_64)
then uninstall and install Ruby versions again will fix the issue.