ASDF VM Version Manager for Ruby Tutorial

Using a version manager is critical if you plan on running different projects from GitHub. A project might not be compatible with the version of Ruby you have installed.

We need a way to switch between versions of Ruby without installing and uninstalling them every time.

I’ll show you how to switch versions easily using ASDF-VM, a version manager for Ruby and other languages.

Make sure your machine doesn’t have Ruby installed. Let’s install ASDF-VM.

Although ASDF-VM is not the only version manager on the block, I prefer it because it is easy to install and use. Other popular version managers like RVM or RBENV also do the job.

I’m using these instructions to install ASDF-VM below.

Open your terminal and clone the latest ASDF-VM branch.

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

Let’s add ASDF-VM to our shell so we can run it from any folder.

echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.bashrc
echo -e '\n. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc

To take effect, close your terminal window and reopen it again.  Run:

asdf

You’ll see something like this:

ASDF-VM doesn’t have a GUI interface and those are the commands you can run it with.

Let’s install Ruby dependencies before installing Ruby.

sudo apt install build-essential
sudo apt install zlib1g-dev libssl-dev libreadline-dev libgdbm-dev

We want to install the ASDF-VM ruby plugin.

asdf plugin-add ruby


Let’s install Ruby through ASDF-VM.  I want to install Ruby version 2.6.2. Other versions are available depending on what you want to run.

asdf install ruby 2.4.4 

Run ASDF again and see other commands available to manage your Ruby package.

asdf
asdf current

This tells you that no version is set for Ruby on this machine.  To check available versions, run:

asdf list ruby

You’ll see 2.6.2. Let’s set it as the global (screenshot shows local) version to use.

Asdf global ruby 2.6.2

Double check:

asdf current

It should say Ruby 2.6.2. To triple check, go ahead and run the version command on Ruby itself in the terminal.

ruby -v

Ruby 2.6.2 is installed and is active.

Share on facebook
Share
Share on linkedin
Share
Share on reddit
Reddit
Share on twitter
Twitter
Nikita Kazakov
Nikita Kazakov

Software Developer and Product Owner.