Asdf: Add command to install latest stable version of a tool

Created on 8 Aug 2017  ·  9Comments  ·  Source: asdf-vm/asdf

Right now it's up to plugins to decide how they list versions. Some list only stable releases, others may list all releases. Some may print out the versions sorted incorrectly. This prevents us from just doing asdf list-all "$tool" | tail -1 to get the latest stable version of a tool.

We need a command that allows us to install the latest stable version of a tool. In order to have such a command we will need to have a latest-stable callback script in each plugin that returns the latest stable version of a tool. Then we can add a --latest flag to the install command so we can do asdf install ruby --latest to install the version of Ruby returned from the Ruby plugin's latest-stable callback. The callback script would need to return the latest stable version of the tool for the given architecture. Some plugins have different versions available for different architectures, so if a plugin does include the latest-stable it must chose to the right version for the architecture.

This latest-stable callback script would start out optional, but could eventually be made a requirement by adding an assertion to the plugin-test command.

Created when reviewing https://github.com/thoughtbot/laptop/pull/502

enhancement proposal

Most helpful comment

@NightMachinary @quintrino What do you think about integrating the logic from xxenv-latest into asdf? I currently use it with pyenv and have been pleased, but I am looking into switching to asdf to handle all the languages I use. It defaults to grabbing the latest numeric version like your Ruby script, but permits an additional parameter by which to filter versions. I have not tested it with rbenv, but I imagine it behaves like:

  • rbenv latest install installs 2.6.4
  • rbenv latest install 2.5 installs 2.5.6
  • rbenv latest install jruby installs jruby-9.2.8.0

An asdf implementation could allow:

  • asdf install ruby latest
  • asdf install ruby latest 2.5
  • asdf install ruby latest jruby

It could also look similar to the existing ref support to avoid an additional parameter:

  • asdf install ruby latest
  • asdf install ruby latest:2.5
  • asdf install ruby latest:jruby

I think this would just require updating the install_tool_version function in install.sh. There could also be a new latest or list-latest function to print the version (similar to list and list-all), which install_tool_version would then leverage to get the version.

All 9 comments

Once the referred issues are resolved, what would be nice is to have a package cleanup command, that retains only the latest minor versions by default, but still allowing the cleanup for major versions from an input flag, and also optionally a way to hold certain packages manually.

While versioning semantics may differ, asdf could just follow semantic versioning, with optional plugin API that can be used to override this behaviour for custom semantics by the plugins.

This should provide the full functionality needed to maintain a sort of rolling release model. Then this tool can fully replace nvm, gvm etc.

Has any progress happened since 2017?

I don't know if it's still under development, but this might help you @NightMachinary

I have a small method I've been using in a ruby file that might be of help to you.

def latest(language)
  `asdf plugin-add #{language} 2> /dev/null`
  versions = `asdf list-all #{language} 2> /dev/null`.split("\n")
  stock_versions = versions.select { |v| v.count('a-zA-Z').zero? }
  latest_version = stock_versions.max_by { |v| Gem::Version.new(v) }
  `asdf install #{language} #{latest_version}`
end

So far it's proven functional for Ruby, Rust, Node, Postgres, Elixir and Elm, but other languages may break it.

(This is slightly modified from the original that I use which just returned the version number but should when run in a ruby file/executable install the latest version)

@quintrino Thanks! I adapted that into a script:

#!/usr/bin/env ruby
def latest(language)
  `asdf plugin-add #{language} 2> /dev/null`
  versions = `asdf list-all #{language} 2> /dev/null`.split("\n")
  stock_versions = versions.select { |v| v.count('a-zA-Z').zero? }
  latest_version = stock_versions.max_by { |v| Gem::Version.new(v) }
  `asdf install #{language} #{latest_version}`
end
latest(ARGV[0])

Great!

One thing to keep in mind is that this only works if the default version of the language doesn't include letters in it's name while the alternate versions do.

So with Ruby, the line
stock_versions = versions.select { |v| v.count('a-zA-Z').zero? }
filters out jruby, mruby and preview versions, but keeps the core versions of 2.6.4.

If the core or default version of a language included letters, this would filter it out.

@NightMachinary @quintrino What do you think about integrating the logic from xxenv-latest into asdf? I currently use it with pyenv and have been pleased, but I am looking into switching to asdf to handle all the languages I use. It defaults to grabbing the latest numeric version like your Ruby script, but permits an additional parameter by which to filter versions. I have not tested it with rbenv, but I imagine it behaves like:

  • rbenv latest install installs 2.6.4
  • rbenv latest install 2.5 installs 2.5.6
  • rbenv latest install jruby installs jruby-9.2.8.0

An asdf implementation could allow:

  • asdf install ruby latest
  • asdf install ruby latest 2.5
  • asdf install ruby latest jruby

It could also look similar to the existing ref support to avoid an additional parameter:

  • asdf install ruby latest
  • asdf install ruby latest:2.5
  • asdf install ruby latest:jruby

I think this would just require updating the install_tool_version function in install.sh. There could also be a new latest or list-latest function to print the version (similar to list and list-all), which install_tool_version would then leverage to get the version.

It seems an improvement to me👍🏼

On Fri, Sep 6, 2019 at 9:34 PM Kevin Lane notifications@github.com wrote:

@NightMachinary https://github.com/NightMachinary @quintrino
https://github.com/quintrino What do you think about integrating the
logic from xxenv-latest
https://github.com/momo-lab/xxenv-latest/blob/master/bin/xxenv-latest
into asdf? I currently use it with pyenv and have been pleased, but I am
looking into switching to asdf to handle all the languages I use. It
defaults to grabbing the latest numeric version like your Ruby script, but
permits an additional parameter by which to filter versions. I have not
tested it with rbenv, but I imagine it behaves like:

  • rbenv latest install installs 2.6.4
  • rbenv latest install 2.5 installs 2.5.6
  • rbenv latest install jruby installs jruby-9.2.8.0

An asdf implementation could allow:

  • asdf install ruby latest
  • asdf install ruby latest 2.5
  • asdf install ruby latest jruby

It could also look similar to the existing ref support to avoid an
additional parameter:

I think this would just require updating the install_tool_version
function in install.sh
https://github.com/asdf-vm/asdf/blob/master/lib/commands/install.sh.
There could also be a new latest or list-latest function to print the
version (similar to list and list-all), which install_tool_version would
then leverage to get the version.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/asdf-vm/asdf/issues/216?email_source=notifications&email_token=AIUL56S4GDXDM5PF2UJ26ADQIKERZA5CNFSM4DWDIAOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6DOKJI#issuecomment-528934181,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AIUL56S4PACD3BRZB332BMTQIKERZANCNFSM4DWDIAOA
.

@NightMachinary @quintrino
tuned your script a bit
https://gist.github.com/dre-hh/88a119bc1e69892e45317eb04c2af9da

can't we add ruby as optional dependency to asdf for implementing latest? 🤣

For those who end up here: here's my bash script for updating every asdf plugin dependency to latest:
https://gist.github.com/ig0rsky/fef7f785b940d13b52eb1b379bd7438d

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jayvdb picture jayvdb  ·  4Comments

gmile picture gmile  ·  3Comments

robsonpeixoto picture robsonpeixoto  ·  4Comments

pachun picture pachun  ·  3Comments

jthegedus picture jthegedus  ·  3Comments