7

Introducing you to asdf-vm

 2 years ago
source link: https://dev.to/fariasmateuss/introducing-you-to-asdf-vm-491d
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Introducing you to asdf-vm

Well, I recently discovered through a video by Fabio Akita, that there is a more practical way to manage versions of programming languages.

We work on several different projects. Some projects are new and use, for example Ruby 2.6.3. But sometimes we need to maintain projects from 3 or 4 years ago that may still be in Ruby 2.4.4 for example. It means that we need to have all of these versions installed on our machine at the same time. The same goes for Javascript or other languages. But a Linux distro's package manager only manages one version. After it updates, the old version no longer exists. So we need an outside way to manage this. Over the years, each language has built its own version manager like RVM and RBENV in Ruby, or Javascript's NVM, or Python's Virtualenv. But it is also a pain to have to remember the syntax and settings of so many different tools. And to save us came the Universal version manager, ASDF.

Managing the managers

asdf is a CLI tool that can manage multiple language runtime versions on a per-project basis. It is like gvm, nvm, rbenv & pyenv (and more) all in one! Simply install your language's plugin!

Installation and first steps

GitHub logo asdf-vm / asdf

Extendable version manager with support for Ruby, Node.js, Elixir, Erlang & more

Manage multiple runtime versions with a single CLI tool, extendable via plugins - docs at asdf-vm.com

asdf is a CLI tool that can manage multiple language runtime versions on a per-project basis. It is like gvm, nvm, rbenv & pyenv (and more) all in one! Simply install your language's plugin!

Why use asdf?

  • single CLI for multiple languages
  • consistent commands to manage all your languages
  • single global config keeping defaults in one place
  • single .tool-versions config file per project
  • support for existing config files .node-version, .nvmrc, .ruby-version for easy migration
  • automatically switches runtime versions as you traverse your directories
  • simple plugin system to add support for your language of choice
  • shell completion available for common shells (Bash, Zsh, Fish)

Documentation

Please head over to the documentation site for more information!

Clone only the latest branch:

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.8.0
Enter fullscreen modeExit fullscreen mode

Then add the following line to your ~/.bashrc file.

. $HOME/.asdf/asdf.sh
Enter fullscreen modeExit fullscreen mode
. $HOME/.asdf/completions/asdf.bash
Enter fullscreen modeExit fullscreen mode

Restart your shell so that PATH changes take effect.

First steps

Now that asdf is properly installed, we can start playing with it. First of all, know that it works with plugins, so first of all you need to install the official asdf plugin for your language, I will use Ruby as an example.

Add a plugin

It is quite simple as you can see

asdf plugin add <name>
# asdf plugin add ruby
Enter fullscreen modeExit fullscreen mode

once added, you can list all language versions. Using the command below

asdf plugin list
# asdf ruby list

or 

asdf list all ruby ou asdf list-all ruby
Enter fullscreen modeExit fullscreen mode

List a language version

To install a version is as simple as

asdf install <name> latest
# asdf install ruby latest

or

asdf install <name> latest:<version>
# asdf install ruby latest:17
Enter fullscreen modeExit fullscreen mode

and finally, to set the installed version.

asdf global <name> <version> [<version>...]
asdf shell <name> <version> [<version>...]
asdf local <name> <version> [<version>...]
# asdf global ruby 2.6.4
Enter fullscreen modeExit fullscreen mode

If you need to unset, use

asdf uninstall <name> <version>
# asdf uninstall ruby 2.6.4asdf plugin update <name>
# asdf plugin update erlang
Enter fullscreen modeExit fullscreen mode

Photo by Carl Raw on Unsplash.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK