The Ruby version you are trying to install does not exist on this stack

When we were trying to deploy the rails application to the Heroku cloud we got into this error. The error is self-descriptive. The app we created on the Heroku cloud was: heroku-18. This is the stack that Heroku uses and behind the scene it uses Ubuntu-18.

Heroku cloud has another stack as of this article. The stack is heroku-16 and it uses Ubuntu-16 behind the scene.

Reason of the error

The rails app we were trying to deploy on Heroku was built with the stack heroku-16. But we were trying to deploy on the stack heroku-18. As soon as we tried to deploy we got the error:

remote:  !     The Ruby version you are trying to install does not exist on this stack.
remote:  !     You are trying to install ruby-2.3.1 on heroku-18.
remote:  !     Ruby ruby-2.3.1 is present on the following stacks:
remote:  !     - cedar-14
remote:  !     - heroku-16

Solution of the error

We had to change the stack using the following command in Heroku.

heroku stack:set heroku-16

This allowed us to change the stack to heroku-16 and we were able to deploy our app to Heroku nicely.