# Linux下安装Ruby
## [Install rbenv](https://github.com/rbenv/rbenv#basic-github-checkout)
```zsh
# Clone rbenv into ~/.rbenv
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
# Optionally, try to compile dynamic bash extension to speed up rbenv. Don't worry if it fails; rbenv will still work normally
$ cd ~/.rbenv && src/configure && make -C src
# Add ~/.rbenv/bin to your $PATH
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
# Set up rbenv in your shell
$ ~/.rbenv/bin/rbenv init
# Follow the printed instructions to set up rbenv shell integration, it looks like this:
$ echo 'eval "$(rbenv init -)"' >> ~/.zshrc
# Verify that rbenv is properly set up using this rbenv-doctor script:
$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
```
## [Install ruby-build plugin](https://github.com/rbenv/ruby-build#readme)
```zsh
# As an rbenv plugin
$ mkdir -p "$(rbenv root)"/plugins
$ git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
```
## [Install Ruby versions](https://github.com/rbenv/rbenv#installing-ruby-versions)
```zsh
# list all available versions
$ rbenv install -l
# install a Ruby version
$ rbenv install 2.5.1
# list all installed Ruby versions
$ rbenv versions
# list current Ruby version
$ rbenv version
# set global version of Ruby to be used in all shells by writing the version name to the `~/.rbenv/version` file
$ rbenv global 2.5.1
# reports the currently configured global version
$ rbenv global
# set a local application-specific Ruby version by writing the version name to a .ruby-version file in the current directory
$ rbenv local 2.5.1
# set a shell-specific Ruby version
$ rbenv shell 2.5.1
# install Ruby gems
$ gem install bundler
```