I use asdf to manage my runtime versions (Ruby and Node). This makes life a lot easier when switching between multiple codebases and allows me to easily to switch machines due to the presence of a .tool-versions file in each of my repositories.

Where this gets a little complicated is creating a new Ruby on Rails project, as my local (in a directory) version of tools may be different to my global (laptop wide) versions.

To ensure I’m not getting versions mixed up, I like to setup my local versions before creating the application.

Setup using asdf

Create a folder from the terminal on your machine and navigate into it.

mkdir my_new_rails_project
cd my_new_rails_project

From here we will tell asdf which versions of Ruby and Node we want to use. I’ve previously tried to also specify the Postgres version too but that caused more issues than it solved.

asdf local ruby 3.3.0
asdf local nodejs 20.11.0

By default the yarn version is usually set to v1.x which is pretty old in comparison to the current v4.x that is available, so lets fix that.

yarn set version stable
yarn -v
# 4.1.0

I sometimes have issues where the above command fails with an error saying that the Node version is incorrect. This can usually be fixed with a asdf reshim nodejs command.

Rails new

You should now be ready to run the rails new command. You may need to install the rails gem for the your version of Ruby - there’s nothing special for you to do here other than following the Rails documentation

When running the rails new command, be sure to run it from the directory that you have manually created. Instead of naming the project in the rails new command you’ll want to use the existing directory. This is achieved by running rails new . rather than something like rails new my_new_rails_project as described in the documentation - the . tells the Rails CLI tool to use the current directory