Maybe you want to install a newer version? Install Ruby on Rails 6

  • Install Ruby on Rails 5:
rvm install ruby-2.7.2
rvm --default use 2.7.2
rvm uninstall 2.7.1
gem install rails -v 5.2.4.3
  • Set up Postgresql:
sudo apt install postgresql libpq-dev
sudo su postgres
createuser --interactive
ubuntu
y 
exit

Extended Tutorial on installing Postgresql