rbenv and Ruby on Rails on Ubuntu 18.04
Adapted from How To Install Ruby on Rails with rbenv on Ubuntu 18.04
Ubuntu 18.04 virtual machine available
- LAMP: Ubuntu 18.04, Apache 2.4, MariaDB 10.5, PHP 7.4.
Goals
- Use
rbenv
to manage the version of Ruby. - Install Ruby on Rails v5+.
Install rbenv and dependencies
Install dependencies
sudo apt-get update
sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev
Install rbenv
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
Append commands to .bashrc
- Add
~/.rbenv/bin
to your$PATH
- Make
rbenv
load automatically
echo '
# Make rbenv load automatically
export RBENV_ROOT="${HOME}/.rbenv"
export PATH="${RBENV_ROOT}/bin:${PATH}"
eval "$(rbenv init -)"
' | tee -a ~/.bashrc
Check it
source ~/.bashrc
type rbenv
Install the ruby-build plugin
This plugin adds the rbenv install
command, which simplifies the installation process for new versions of Ruby.
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
Install Ruby
List available Ruby versions:
rbenv install -l
Install v2.6.4 and make it global:
rbenv install 2.6.4
rbenv global 2.6.4
ruby -v
To uninstall a Ruby version:
rbenv uninstall 2.5.0
Install Bundler
Suppress gem documentation generation:
echo "gem: --no-document" | tee ~/.gemrc
Check where gems are installed:
gem env home
Bundler is a tool that manages gem dependencies for projects.
gem install bundler
Install Ruby on Rails
List available Rails versions:
gem search '^rails$' --all
Install a v5+ version:
gem install rails -v 5.2.3
rails -v
Maintain rbenv shims:
rbenv rehash