DEV Community

Mr F.
Mr F.

Posted on

Manage your runtime environments using ASDF and not NVM or RVM etc...

Many of us have used rvm or rbenv to manage Ruby, nvm or n to manage our Node installs, pyenv for Python. The problem is when you need to add other things into the mix like gvm for Go, the list goes on.

crazy

ASDF to the rescue!

Manage multiple runtime versions with a single CLI tool

ASDF allows you to manage many environments on a per project basis. ASDF has done for my project management what homebrew did for my Mac.

Let's say for example you had RVM and NVM installed and Dart was done via shell scripts. Sure, you're already on top of it - but why accept the pain involved with managing them on top of the environments themselves?

You may not suffer from any of the above and just have one environment to handle, but nonetheless, make it easy for someone who has to manage or maintain your work after you're done with it.

If you're working on or maintaining multiple projects with a team of people, asdf will make all of your lives much easier.

I'll demonstrate how easy it is to take control and get some of your sanity back.
We'll work with Node for this example.

Install asdf

via Homebrew

brew install asdf
Enter fullscreen mode Exit fullscreen mode

If you are on Linux or are using Linux subsystem on Windows or don't use homebrew on macOS, you can install via git.

Update your shell to handle asdf

These are for anyone who installed via homebrew. If you installed via git, follow the instructions on the asdf website.

BASH

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

ZSH

echo -e "\n. $(brew --prefix asdf)/asdf.sh" >> ~/.bash_profile
echo -e "\n. $(brew --prefix asdf)/etc/bash_completion.d/asdf.bash" >> ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

Install plugin dependencies for homebrew

You might not have all the dependencies installed, so you need to run:

brew install \
  coreutils automake autoconf openssl \
  libyaml readline libxslt libtool unixodbc \
  unzip curl
Enter fullscreen mode Exit fullscreen mode

Install a language plugin

ASDF comes with extensive language support via it's plugin system

asdf plugin-add nodejs https://github.com/asdf-vm/asdf-nodejs.git
Enter fullscreen mode Exit fullscreen mode

For nodejs we will also have to add the release team's OpenPGP keys to main keyring:

bash ~/.asdf/plugins/nodejs/bin/import-release-team-keyring
Enter fullscreen mode Exit fullscreen mode

List all versions for this package

asdf list-all nodejs
Enter fullscreen mode Exit fullscreen mode

This will output all the versions you can install via asdf.

Install the version you need

 asdf install nodejs 13.3.0
Enter fullscreen mode Exit fullscreen mode

Let's set a system wide version, which will be the default version.

asdf global nodejs 13.3.0
Enter fullscreen mode Exit fullscreen mode

To install a different version:

 asdf install nodejs 7.9.0
Enter fullscreen mode Exit fullscreen mode

Now set it in your current project or directory by:

asdf local nodejs 7.9.0
Enter fullscreen mode Exit fullscreen mode

How to store your settings

You can store your settings for the project by creating a .tool-versions file.

inside your current project add the following setting:

nodejs 7.9.0
Enter fullscreen mode Exit fullscreen mode

If you commit this to your project and someone else picks it up, asdf will understand what version to use and prompt you to install it if necessary.

Keep asdf up to date

Now you have one manager to manage your multiple development environments. You only need to keep asdf up to date, which is easy peasy.

via homebrew:

brew upgrade asdf
Enter fullscreen mode Exit fullscreen mode

or via git

asdf update
Enter fullscreen mode Exit fullscreen mode

Rinse and repeat!

You can rinse and repeat this for as many environments as you need, in as many projects as necessary.

How easy is that!

ring

Top comments (4)

Collapse
 
truongnguyen012 profile image
TruongNguyen012

I got this error when install nodejs by asdf install nodejs 14.10.0:
Authenticity of checksum file can not be assured! Please be sure to check the README of asdf-nodejs in case you did not yet import the needed PGP keys. If you already did that then that is the point to become SUSPICIOUS! There must be a reason why this is failing. If you are installing an older NodeJS version you might need to import OpenPGP keys of previous release managers. Exiting.

Please help!

Collapse
 
0xdonut profile image
Mr F.

did you add the pgp keys to your bash/zsh file?
if you did you will need to re-source the file or open a new terminal and it should resolve your problem

Collapse
 
blemoine167 profile image
blemoine167

Thank you for the post, i just discovered asdf cause of your post. Some things changed in the install process so the post is more or less obsolete now. Please refer to the official doc : asdf-vm.com/#/core-manage-asdf-vm?....

Collapse
 
muescha profile image
Michael • Edited

is it right that the ZSH example pipes to .bash_profile? should this not be the .zshrc?