First of all try to find out if you have that version installed. In this case, run this command:
gem list rails
You should see the list of gems you have installed on your computer that contains the word 'rails' in the name and also you will see the version (or versions) of that gems that you have installed.
Find where does it says rails
and there you will find all the versions you have installed, in my case it is: rails (5.2.0, 5.1.6, 5.1.4, 5.1.3, 5.1.2, 5.1.1, 5.0.6, 5.0.3, 5.0.1, 5.0.0.1, 4.2.0)
So I can run the command rails _4.2.0_ new myapp
and it will create a new app using rails 4.2.0.
If you don't have that version installed just run the command gem install rails -v 4.2.3
And there you have it.
References: