Install rbenv on Ubuntu with rbenv-installer
# install rbenv and ruby-build
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash
# setup rbenv in your shell
rbenv init
author: Paul Kim
categories: ruby, rbenv
tags: ruby, rbenv
# Install rbenv and ruby-build
brew install rbenv
# setup rbenv in your shell
rbenv init
# install rbenv and ruby-build
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash
# setup rbenv in your shell
rbenv init
.bash_profile
on macOS# automatically load rbenv by appending the following to ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
# reload .bash_profile so that PATH changes take effect
source ~/.bash_profile
Note: your .bash_profile file should contain the following:
# rbenv
eval "$(rbenv init -)"
.bashrc
on Ubuntu and Windows 10 with Windows Subsystem for Linux# add ~/.rbenv/bin to your $PATH for access to the 'rbenv' command-line utility
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
# automatically load rbenv by appending the following to ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
# change the default gem path to ~/gems
# (recommended to avoid file permissions problems and using `sudo`)
echo '# Install Ruby Gems to ~/gems' >> ~/.bashrc
echo 'export GEM_HOME="$HOME/gems"' >> ~/.bashrc
echo 'export PATH="$HOME/gems/bin:$PATH"' >> ~/.bashrc
# restart your shell so that PATH changes take effect
exec $SHELL
Note: your .bashrc
file should contain the following:
# rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
# install Ruby Gems to ~/gems
export GEM_HOME=$HOME/gems
export PATH=$HOME/gems/bin:$PATH
First, disable rbenv by removing the following two lines from your shell startup config file (.bash_profile or .bashrc
):
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
Then:
# remove rbenv root directory
rm -rf `rbenv root`
# if you installed rbenv using Homebrew
brew uninstall rbenv
sudo apt install -y build-essential
sudo apt install -y libssl-dev zlib1g-dev # ubuntu
sudo dnf install -y libssl-dev zlib1g-dev # fedora
# install Ruby 2.5.8
rbenv install 2.5.8
# install Ruby 2.7.2
rbenv install 2.7.2
# set Ruby 2.7.2 as the global Ruby version
rbenv global 2.7.2
# list all ruby versions known to rbenv with an asterisk next to the currently active version.
rbenv versions
# display the currently active ruby version
rbenv version
# print ruby version
ruby -v
# Check your install
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
# check that default gem paths point to your home directory by default
gem env
# print gem version
gem -v
# install bundler and jekyll on ubuntu
gem install bundler jekyll
# install ruby gems locally on mac
gem install --user-install bundler jekyll
# list all available rbenv commands
rbenv commands
# get global ruby version
rbenv global
# set global ruby version to 2.7.2
rbenv global 2.7.2
# set global ruby version to system default
rbenv global system
# get local ruby version
rbenv local
# set local ruby version to 2.7.2
rbenv local 2.7.2
# unset local ruby version
rbenv local --unset
# get shell ruby version
rbenv shell
# set shell ruby version to 2.7.2
rbenv shell 2.7.2
# unset shell ruby version
rbenv shell --unset
# list only stable releases for each ruby implementation
rbenv install -l
# list all ruby versions available for installation
rbenv install --list-all
# install ruby version 2.7.2
rbenv install 2.7.2
# uninstall ruby version 2.7.2
rbenv uninstall 2.7.2
# install shims for all Ruby executables known to rbenv
# run this command after you install a new version of Ruby or install a gem that provides commands
rbenv rehash
# list all ruby versions known to rbenv with an asterisk next to the currently active version.
rbenv versions
# display the currently active ruby version
rbenv version