How to try rails 8

Hi, I’ve already got rails 7.1.x installed as a gem in a ruby 3.3.x rbenv.

How do I try out rails 8 (on a new project) without overriding the previous 7.x stable gem?

(E.g. install separate gem store? or install from where I can use a FQ path for rails new ...

I’m used to creating a virtual-env in python so project-specific libs go in there, but i can’t see that there is a similar pattern for rbenv or rvm.

Thanks

Rob

Hi @r952, what OS are you using?

In general, you can use gem install rails -v 8.0.0.beta1. or gem install rails --prerelease You can use rbenv to specify which ruby version you want to use for your project, or in general.

Please check:

Thank you @dalibor.os

I’m on MacOS & linux.

In fact I did this as you described but now my rails binary that’s in the PATH set by rbenv is Rails v8

How do I get back to Rails 7 for other projects? Or am I required to … gem install rails -v <version i need right now> and flip-flop around forcing gems to whatever version I need at the time?

Thanks again

R

You can call a specific version of rails by adding the version string after it in the command line, like this: bundle exec rails _7.1.2_ new whatever... (obviously, use a version you have installed, see gem list rails for your local versions. The underscores are actually important in this case, not placeholders for this answer.

Walter

1 Like

This is great, thank you @walterdavis

So it’s bundler that can negotiate the various installed versions. Very useful step-up on the learning curve! Cheers

R

Actually, I think I may have misspoken here: it’s not bundler that does this, and unless you have a Gemfile in the directory where you are running Rails, this may not work, either. Try it without the bundle exec prefix. It’s just a feature of the rails executable itself.

Walter

1 Like

@walterdavis that’s it!

Looks like something called railties knits the desired version with the installed Gem.

rob@quark /tmp % which rails
/Users/rob/.rbenv/shims/rails

rob@quark /tmp % rails -v
Rails 8.0.0.rc1

rob@quark /tmp % gem list ^rails$

*** LOCAL GEMS ***

rails (8.0.0.rc1, 7.2.1.2, 7.1.3.2, 7.1.3)

rob@quark /tmp % rails _7.2.1.2_ -v
Rails 7.2.1.2

rob@quark /tmp % rails _7.2.1.X_ -v
/Users/rob/.rbenv/versions/3.3.0/lib/ruby/3.3.0/rubygems.rb:259:in `find_spec_for_exe': can't find gem railties (= 7.2.1.X) with executable rails (Gem::GemNotFoundException)
	from /Users/rob/.rbenv/versions/3.3.0/lib/ruby/3.3.0/rubygems.rb:278:in `activate_bin_path'
	from /Users/rob/.rbenv/versions/3.3.0/bin/rails:25:in `<main>'

Thanks again

Rob