

In this post, rbenv is used to install Rails6.0.0 and Ruby2.7.1
First, update your packages
sudo apt-get update
Then Install these prerequisites
sudo apt-get install git -y
sudo apt-get install gcc -y
sudo apt-get install autoconf -y
sudo apt-get install bison -y
sudo apt-get install build-essential -y
sudo apt-get install libssl-dev -y
sudo apt-get install libyaml-dev -y
sudo apt-get install libreadline6-dev -y
sudo apt-get install zlib1g-dev -y
sudo apt-get install libncurses5-dev -y
sudo apt-get install libffi-dev -y
sudo apt-get install libgdbm6 -y
sudo apt-get install libgdbm-dev -y
sudo apt-get install libdb-dev -y
Package | Description |
Git | Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. |
Gcc | For Compilation |
autoconf | An automatic configure script builder |
bison | A general-purpose parser generator that converts a grammar description for an LALR(1) context-free grammar into a C program to parse that grammar. |
build-essential | |
libssl | Secure Sockets Layer toolkit |
libyaml | A C library for parsing and emitting YAML |
libreadline6 | GNU readline and history libraries, run-time libraries |
zlib1g | A runtime compression library |
libncurses5 | This is shared libraries for terminal handling |
libffi | A module to check availability of a library for FFI |
libgdbm6 | GNU dbm database routines |
libgdbm | GNU dbm database routines |
libdb | Berkeley Database Libraries for C++ |
Next, we install rbenv itself
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
Install your desired version if ruby
rbenv install 2.7.1
Make the installed version of ruby Global so it can be used everywhere
rbenv global 2.7.1
Finally install Rails 6.0.0 or any supported version you desire and then check its version
gem install bundler -v 2.1.4
ruby -v
gem install rails -v 6.0.0
rails -v
Here is the complete shell script.
#!/bin/bash
sudo apt-get update
echo "--------------"
echo "Prerequisites"
echo "Get updated Rails prerequisites from https://github.com/rbenv/ruby-build/wiki#suggested-build-environment"
echo "--------------"
sudo apt-get install git -y
sudo apt-get install gcc -y
sudo apt-get install autoconf -y
sudo apt-get install bison -y
sudo apt-get install build-essential -y
sudo apt-get install libssl-dev -y
sudo apt-get install libyaml-dev -y
sudo apt-get install libreadline6-dev -y
sudo apt-get install zlib1g-dev -y
sudo apt-get install libncurses5-dev -y
sudo apt-get install libffi-dev -y
sudo apt-get install libgdbm6 -y
sudo apt-get install libgdbm-dev -y
sudo apt-get install libdb-dev -y
echo "--------------"
echo "Installing Ruby using rbenv along with its setup"
echo "--------------"
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
rbenv install 2.7.1
rbenv global 2.7.1
gem install bundler -v 2.1.4
ruby -v
gem install rails -v 6.0.0
rails -v
Furthermore, to uninstall a specific version of Ruby, you can do this
rbenv uninstall 2.7.1