banner

I’ve realized that a lot of people have a hard time configuring Node and Ruby.

While I’ve been used to install nvm and rvm to manage each language (even because I’m the one building Ubuntu binaries in the rvm team), but asdf is a multiple runtime version manager that can handle both.

Install asdf

You’ll need curl and git installed. If not installed, install with:

sudo apt install curl git

Now install asdf, but check which is the current version in the Official Download instructions:

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0

Now let’s configure environment variables for asdf home and bash completion:

echo '. "$HOME/.asdf/asdf.sh"' >> .bashrc
echo '. "$HOME/.asdf/completions/asdf.bash"' >> .bashrc
source .bashrc

Install Node

Install suggested Node dependencies:

sudo apt install python3 g++ make python3-pip

Add the NodeJS plugin:

asdf plugin add nodejs

Install Latest available Node version:

asdf install nodejs latest

Set a global (default) version for Node:

asdf global nodejs latest

Install Ruby and Rails

Install suggested Ruby dependencies:

sudo apt install autoconf patch build-essential rustc libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev uuid-dev

Add the Ruby plugin:

asdf plugin add ruby

Install Latest available Node version:

asdf install ruby latest

Set a global (default) version for Ruby:

asdf global ruby latest

In order to create a Rails project, you’ll need the rails gem installed:

gem install rails

More about asdf

All asdf commands are listed here: https://asdf-vm.com/manage/commands.html.

In summary:

  • Check asdf installed version: asdf version
  • List installed plugins: asdf plugin list
  • List available plugin: asdf plugin list all
  • Check current plugin version: asdf current <plugin>
  • List installed plugin versions: asdf list <plugin>
  • List all available plugin versions: asdf list all <plugin>
  • Add a new plugin: asdf plugin add <plugin>
  • Remove a plugin: asdf plugin remove <plugin>
  • Update to stable: asdf update
  • Update to the latest: asdf update --head

You can setup asdf in 3 levels:

  • Global: asdf global <plugin> <version>
  • Shell session: asdf shell <plugin> <version>
  • Local folder: asdf local <plugin> <version>

Local will create a .tool-versions file.

Done!

Bonus: all above steps in a single take (just make sure to replace v0.14.0 with the latest asdf version):

sudo apt install curl git python3 g++ make python3-pip autoconf patch build-essential rustc libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev uuid-dev
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0
echo '. "$HOME/.asdf/asdf.sh"' >> .bashrc
echo '. "$HOME/.asdf/completions/asdf.bash"' >> .bashrc
source .bashrc
asdf plugin add ruby
asdf plugin add nodejs
asdf install nodejs latest
asdf global nodejs latest
asdf install ruby latest
asdf global ruby latest
gem install rails

That is it. Now check the next post about how to setup a Rails + Vite environment.

Troubleshooting

No preset version installed for command rails

If you try to run rails in our project and get this:

No preset version installed for command rails
Please install a version by running one of the following:

asdf install ruby <your-project-version>

or add one of the following versions in your config file at /home/rael/.tool-versions
ruby <last-installed-version>

I’m supposing, of course, you already have installed the project required ruby version.

Fix it with:

asdf reshim ruby

Source: StackOverflow