Rbenv is used to manage Ruby versions. rbenv is used to manage ruby versions.
Rbenv is used to manage the installation and use of multiple versions of ruby in the user directory. It can be used with rvm. The specific differences between rbenv and rvm are described in the document and discussed in the community.
System Requirements
OSX: Find a good place on the Internet. Download xcode. app from the app store and run it after installation. Install Command Line Tools in Downloads.
Linux: Install the development environment (compile the link tool and ruby dependencies). If jruby has jre, you can.
Install rbenv
You can directly use homebrew to install osx. The following is a manual installation process (replace zsh with your shell configuration file without zsh)
git clone git: //github.com/sstephenson/rbenv.git ~ / .rbenv
# Used to compile and install ruby
git clone git: //github.com/sstephenson/ruby-build.git ~ / .rbenv / plugins / ruby-build
# Used to manage gemset, optional, because bundler is not necessary
git clone git: //github.com/jamis/rbenv-gemset.git ~ / .rbenv / plugins / rbenv-gemset
# After installing the gem through the gem command, you do not need to manually enter the rbenv rehash command, recommended
git clone git: //github.com/sstephenson/rbenv-gem-rehash.git ~ / .rbenv / plugins / rbenv-gem-rehash
# Update rbenv and all plugins via rbenv update command, recommended
git clone https://github.com/rkh/rbenv-update.git ~ / .rbenv / plugins / rbenv-update
Then put the following code in ~ / .bash_profile
export PATH = "$ HOME / .rbenv / bin: $ PATH"
eval "$ (rbenv init-)"
Note that Unubtu should be placed in ~ / .bashrc, the zsh user is ~ / .zshrc
Then restart a terminal to execute rbenv.
use
Install ruby
rbenv install --list # List all ruby versions
rbenv install 1.9.3-p392 # install 1.9.3-p392
rbenv install jruby-1.7.3 # install jruby-1.7.3
List version
rbenv versions # List installed versions
rbenv version # List the version in use
Set version
rbenv global 1.9.3-p392 # Use 1.9.3-p392 by default
rbenv shell 1.9.3-p392 # The current shell uses 1.9.3-p392, will set a `RBENV_VERSION` environment variable
rbenv local jruby-1.7.3 # The current directory using jruby-1.7.3 will generate a `.rbenv-version` file
Solve the method of compiling Ruby under MacOSX and unable to input Chinese in irb
Install readline of homebrew, then enter the source directory, recompile and install readline.bundle
brew install readline
brew link readline
cd src / ruby-1.9.3-p392 / ext / readline
ruby extconf.rb --with-readline-dir = $ (brew --prefix readline)
make install
Solution under rbenv
brew install readline
CONFIGURE_OPTS = "-disable-install-doc --with-readline-dir = $ (brew --prefix readline)" rbenv install 1.9.3-p392
For questions about ruby-2.0.0-p0 on OS X 10.7+, see: https://github.com/sstephenson/ruby-build/wiki
other
rbenv rehash # This command must be executed whenever the ruby version is switched and bundle install is executed
rbenv which irb # List the full path of the irb command
rbenv whence irb # List the version containing the irb command
Use gemset under rbenv
Introduction
The most convenient in rvm is gemset. In fact, rbenv can also use gemset through plugins
installation
If you use brew under MacOS, you can do it with one command
brew install rbenv-gemset
use
Create a gemset
rbenv gemset create 1.9.3-p392 ruby-china
Specific method of use
In the root directory of the project, put the name of the gemset you want to use in the .rbenv-gemsets file. When there is a .rbenv-gemsets file, executing the bundle command is to operate the set gemset
echo ruby-china> .rbenv-gemsets
When there is no .rbenv-gemsets file in the current directory, when executing the bundle command (without specifying the --path parameter), it is the gemset for the current version of Ruby. It is equivalent to the role of global gemset in rvm