I was able to update rails to version 5.1.4 after doing the following;
sudo apt-get install ruby-dev zlib1g-dev libizma-dev
sudo gem install rails --version=5.1.4
then when I ran : rails server it said I needed to run: bundle install
Now when I run rails server it works and localhost:3000 produces the correct test_app page with the Rails logo and Yay! You're on Rails!