Use rbenv to pick a Ruby version for your application and guaranteethat your development environment matches production. Put rbenv to workwith Bundler for painless Ruby upgrades andbulletproof deployments.
Groom your app’s Ruby environment with rbenv.
Apr 12, 2012 Hi I've been using rbenv on Mac OS X with no issues for quite a while but I just moved to archlinux and I'm having a few issues with 1.8.7 and system ruby. For installing 1.8.7 First I needed a patched version for archlinux and I used th. Bundle -version # command not found: rbenv rehash: bundle -version # 1.0.15 # Set a per-project Ruby version: cd /myapp: rbenv set-local 1.8.7-p352: ruby -version # 1.8.7 # Other commands: rbenv prefix # show the prefix path for the current Ruby version: rbenv version # show the current Ruby version: rbenv versions # show all installed.
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.
Table of Contents
How It Works
At a high level, rbenv intercepts Ruby commands using shimexecutables injected into your
PATH , determines which Ruby versionhas been specified by your application, and passes your commands alongto the correct Ruby installation.
Understanding PATH
When you run a command like
ruby or rake , your operating systemsearches through a list of directories to find an executable file withthat name. This list of directories lives in an environment variablecalled PATH , with each directory in the list separated by a colon:
Directories in
PATH are searched from left to right, so a matchingexecutable in a directory at the beginning of the list takesprecedence over another one at the end. In this example, the/usr/local/bin directory will be searched first, then /usr/bin ,then /bin .
Understanding Shims
rbenv works by inserting a directory of shims at the front of your
PATH :
Through a process called rehashing, rbenv maintains shims in thatdirectory to match every Ruby command across every installed versionof Ruby--
irb , gem , rake , rails , ruby , and so on.
Shims are lightweight executables that simply pass your command alongto rbenv. So with rbenv installed, when you run, say,
rake , youroperating system will do the following:
Choosing the Ruby Version
When you execute a shim, rbenv determines which Ruby version to use byreading it from the following sources, in this order:
Locating the Ruby Installation
Once rbenv has determined which version of Ruby your application hasspecified, it passes the command along to the corresponding Rubyinstallation.
Each Ruby version is installed into its own directory under
~/.rbenv/versions . For example, you might have these versionsinstalled:
Version names to rbenv are simply the names of the directories in
~/.rbenv/versions .
Installation
Compatibility note: rbenv is incompatible with RVM. Please make sure to fully uninstall RVM and remove any references to it from your shell initialization files before installing rbenv.
Homebrew on macOS
If you're on macOS, we recommend installing rbenv withHomebrew.
Note that this also installs
ruby-build , so you'll be ready to install other Ruby versions out of the box.
Follow the printed instructions to set up rbenv shell integration.
Upgrading with Homebrew
To upgrade to the latest rbenv and update ruby-build with newly releasedRuby versions, upgrade the Homebrew packages:
Basic GitHub Checkout
For a more automated install, you can userbenv-installer.If you prefer a manual approach, follow the steps below.
This will get you going with the latest version of rbenv without needinga systemwide install.
Follow the printed instructions to set up rbenv shell integration.
Upgrading with Git
If you've installed rbenv manually using Git, you can upgrade to thelatest version by pulling from GitHub:
Updating the list of available Ruby versions
If you're using the
rbenv install command, then the list of available Ruby versions is not automatically updated when pulling from the rbenv repo. To do this manually:
How rbenv hooks into your shell
Skip this section unless you must know what every line in your shellprofile is doing.
rbenv init is the only command that crosses the line of loadingextra commands into your shell. Coming from RVM, some of you might beopposed to this idea. Here's what rbenv init actually does:
Run
rbenv init - for yourself to see exactly what happens under thehood.
Installing Ruby versions
The
rbenv install command doesn't ship with rbenv out of the box, butis provided by the ruby-build project. If you installed it eitheras part of GitHub checkout process outlined above or via Homebrew, youshould be able to:
Alternatively to the
install command, you can download and compileRuby manually as a subdirectory of ~/.rbenv/versions/ . An entry inthat directory can also be a symlink to a Ruby version installedelsewhere on the filesystem. rbenv doesn't care; it will simply treatany entry in the versions/ directory as a separate Ruby version.
Installing Ruby gems
Once you've installed some Ruby versions, you'll want to install gems.First, ensure that the target version for your project is the one you want bychecking
rbenv version (see Command Reference). Selectanother version using rbenv local 2.0.0-p247 , for example. Then, proceed toinstall gems as you normally would:
You don't need sudo to install gems. Typically, the Ruby versions will beinstalled and writeable by your user. No extra privileges are required toinstall gems.
Check the location where gems are being installed with
gem env :
Uninstalling Ruby versions
As time goes on, Ruby versions you install will accumulate in your
~/.rbenv/versions directory.
To remove old Ruby versions, simply
rm -rf the directory of theversion you want to remove. You can find the directory of a particularRuby version with the rbenv prefix command, e.g. rbenv prefix1.8.7-p357 .
The ruby-build plugin provides an
rbenv uninstall command toautomate the removal process.
Uninstalling rbenv
The simplicity of rbenv makes it easy to temporarily disable it, oruninstall from the system.
rbenv will still be accessible on the command line, but your Ruby apps won't be affected by version switching.
If you've installed rbenv using a package manager, as a final step perform the rbenv package removal. For instance, for Homebrew:
Command ReferenceChecking For Rbenv Shims In Path Not Found
Like
git , the rbenv command delegates to subcommands based on itsfirst argument. The most common subcommands are:
rbenv local
Sets a local application-specific Ruby version by writing the versionname to a
.ruby-version file in the current directory. This versionoverrides the global version, and can be overridden itself by settingthe RBENV_VERSION environment variable or with the rbenv shell command.
When run without a version number,
rbenv local reports the currentlyconfigured local version. You can also unset the local version:
rbenv global
Sets the global version of Ruby to be used in all shells by writingthe version name to the
~/.rbenv/version file. This version can beoverridden by an application-specific .ruby-version file, or bysetting the RBENV_VERSION environment variable.
The special version name
system tells rbenv to use the system Ruby(detected by searching your $PATH ).
When run without a version number,
rbenv global reports thecurrently configured global version.
rbenv shell
Sets a shell-specific Ruby version by setting the
RBENV_VERSION environment variable in your shell. This version overridesapplication-specific versions and the global version.
When run without a version number,
rbenv shell reports the currentvalue of RBENV_VERSION . You can also unset the shell version:
Note that you'll need rbenv's shell integration enabled (step 3 ofthe installation instructions) in order to use this command. If youprefer not to use shell integration, you may simply set the
RBENV_VERSION variable yourself:
rbenv versions
Lists all Ruby versions known to rbenv, and shows an asterisk next tothe currently active version.
rbenv version
Displays the currently active Ruby version, along with information onhow it was set.
rbenv rehash
Installs shims for all Ruby executables known to rbenv (i.e.,
~/.rbenv/versions/*/bin/* ). Run this command after you install a newversion of Ruby, or install a gem that provides commands.
rbenv which
Displays the full path to the executable that rbenv will invoke whenyou run the given command.
rbenv whence
Lists all Ruby versions with the given command installed.
Environment variables
You can affect how rbenv operates with the following settings:
Development
The rbenv source code is hosted onGitHub. It's clean, modular,and easy to understand, even if you're not a shell hacker.
Tests are executed using Bats:
Please feel free to submit pull requests and file bugs on the issuetracker.
Updated December 15th, 2013:
Updated July 9th, 2013:
Out of the box, Ruby does not provide a mechanism to support multipleinstalled versions. Rbenv makesmanaging multiple versions of Ruby easy. It’s a great way to work oncurrent development projects using Ruby 1.9.x and be able to switch toRuby 2.0.x for new work. Rbenv is a lightweight alternative toRuby Version Manager (RVM). Rbenv does not includea way to manage gems, like with RVM, though most people prefer to useBundler gem management instead.
Rbenv is supported on Linux and Mac OS X. Rbenv doesn’t work on Windows (andisn’t really necessary on Windows as there is no system Ruby on Windows).On Windows, the RubyInstaller and/orPik are both good alternatives towork with multiple versions of Ruby on the same box.
NOTE: Rbenv is incompatible with RVM because RVM overrides the
gem command with a function. If you want to switch to Rbenv,make sure you uninstall RVM first. Run the following commands to uninstallRVM:
Then remove/comment out the RVM loader line in
.bash_profile and/or .bashrc
Install Rbenv and Ruby 1.9.x - Mac OS X
First you’ll need to install a C compiler and some other command line toolsto build Ruby from source. You’ll need to install the Xcode Command LineTools:
Mac OS X Mavericks 10.9
If you are using the latest version of Mac OS X Mavericks, it has supportfor downloading the Xcode command line tools directly from a Terminal window.Run the following on a command line:
Checking For Rbenv Shims In Path Not Found Mac
You will be prompted to either click on
Install to just install the commandline developer tools or click on Get Xcode to install both Xcode and thecommand line developer tools. It can be handy to have Xcode as well, butit is a rather large multi-gigabyte download and not really necessary forRuby development. So if you want to get going quickly, just click on theInstall button:
Mac OS X Snow Leopard 10.8 (and earlier)
Versions of Mac OS X prior to Mavericks, like Snow Leopard do not havebuilt-in support for downloading the Xcode command line developer tools, but youcan download them directly from the Apple Developer web sitedeveloper.apple.com/downloads.Here are the current direct download links for the Xcode command line toolsas of this writing. Download the applicable package for your version ofMac OS X:
Once you have downloaded the .dmg file, double-click on the .dmg to open it,then double-click on the .mpkg file to run the Command Line Tools installer:
If you have time to install Xcode, it’s handy to have it around, though notreally required for Ruby development. If you are running Mac OS X MountainLion 10.8, you will need to make sure that you have OS X version 10.8.4 orlater to install Xcode, otherwise the App Store will issue the followingcomplaint:
Download and install the latest version of Xcode from the App Store.Then install the Command Line Tools by choosing the menu item
Xcode -> Preferences.. to display the Downloads dialog.Click on the Downloads tab, then click on the download arrow to the rightof the Command Line Tools component to install.
Next, you’ll need to install the Homebrew package manager to get all thedependencies needed to compile Ruby from source. While you could managethese dependencies by hand, using a package manager is a better idea, aspackage managers know how to uninstall what they install.
Run the following command to install Homebrew:
Run
brew doctor and address any issues it discovers. Whenall is well, you should see:
Next, install the additional dependencies to compile Ruby from source:
And now install
rbenv and the ruby-build plugin:
Add
rbenv init to your shell to enable shims and autocompletion:
Restart shell as a login shell so that the PATH changes take effect:
Install the latest version of ruby 1.9.x (at the time of this writing 1.9.3-p484)
Rebuild the shim executable
You’ll need to run
rbenv rehash every time you install a new version of Rubyor install a new gem.
Set the latest version of ruby to be the default version of ruby
Verify the ruby install. If everything was installed correctly, the
ruby -v command should report that version 1.9.3p484 is installed.
Install Bundler - Mac OS X
You’ll need to use Bundler to manage gems. Installinga gem is also a good way to ensure that you’ve installed most of the Rubyprerequisites.
First, make sure you update to the latest version of Rubygems:
Then install the
bundler gem. If the gem install command reportsSuccessfully installed you’re good to go:
Install Ruby 2.0.0 - Mac OS X
As of this writing, Ruby 2.0.0-p353 is the latest version of Ruby 2.0.0.Use
rbenv install --list to print out the available versions. To install:
To verify the install:
![]()
If you want to make Ruby 2.0.0 the global default version of ruby:
Upgrade Rbenv - Mac OS X
To upgrade rbenv via homebrew:
Remove Rbenv - Mac OS X
Uninstall the packages you installed via homebrew:
Free pdf viewer for mac os x windows 10. Remove the following directory:
And remember to remove whatever you added to
$HOME/.bash_profile
Install Rbenv and Ruby 1.9.x - Linux
Make sure the prerequisite packages are installed.
Ubuntu prerequisites:
RHEL/CentOS prerequisites:
![]()
Download the rbenv source distribution to$HOME/.rbenv:
Add $HOME/.rbenv/bin to your $PATH
Add
rbenv init to your shell to enable shims and autocompletion:
Rbenv Shims In Path Not Found
Restart shell as a login shell so that the PATH changes take effect:
Install the
ruby-build plugin, which provides anrbenv install command to simplify the process of compilingand install new Ruby versions:
Install the latest version of ruby 1.9.x (at the time of this writing 1.9.3-p484)
Rebuild the shim executable
You’ll need to run
rbenv rehash every time you install a newversion of Ruby or install a new gem.
Set the latest version of ruby to be the default version of ruby
Verify the ruby install. If everything was installed correctly, the
ruby -v command should report that version 1.9.3p484 is installed.
Install Bundler - Linux
You’ll need to use Bundler to manage gems.Installing a gem is also a good way to ensure that you’ve installed mostof the Ruby prerequisites.
First, make sure you update to the latest version of Rubygems:
Then install the
bundler gem. If the gem install command reportsSuccessfully installed you’re good to go:
Install Ruby 2.0.0 - Linux
As of this writing, Ruby 2.0.0-p353 is the latest version of Ruby 2.0.0.Use
rbenv install --list to print out the available versions. To install:
To verify the install:
If you want to make Ruby 2.0.0 the global default version of ruby (butcurrently Chef requires Ruby 1.9.x):
Upgrade Rbenv - Linux
Since Rbenv is a Git repository, upgrading is just a matter of refreshing thesource:
Remove Rbenv - Linux
To uninstall/remove Rbenv, remove the following directory:
And remember to remove whatever you added to
$HOME/.bash_profile
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |