asdf icon indicating copy to clipboard operation
asdf copied to clipboard

bug: asdf 0.10.1 can't find the commands directory on linux or macos using homebrew and fish

Open nathanpalmer opened this issue 2 years ago • 15 comments

Describe the Bug

I just installed asdf through homebrew on linux using the fish shell. When I run asdf it tells me this

/home/linuxbrew/.linuxbrew/Cellar/asdf/0.10.1/libexec/bin/asdf: line 82: /home/linuxbrew/.linuxbrew/opt/asdf/lib/commands/command-help.bash: No such file or directory

the lib directory just has two files in it, no subdirectories. ls -l /home/linuxbrew/.linuxbrew/opt/asdf/lib/

asdf.fish
asdf.sh

I can tell that /home/linuxbrew/.linuxbrew/opt/asdf/libexec/lib has a commands directory, but it's not looking in the libexec subfolder.

I can get this to work by editing

libexec/bin/asdf

adding libexec to the asdf_cmd_dir

find_asdf_cmd() {
  local asdf_cmd_dir
  asdf_cmd_dir="$(asdf_dir)/lib/commands"
find_asdf_cmd() {
  local asdf_cmd_dir
  asdf_cmd_dir="$(asdf_dir)/libexec/lib/commands"

and then editing libexec/lib/commands/command-help.bash

adding libexec to the help.txt path

asdf_help() {
  printf "version: %s\\n\\n" "$(asdf_version)"
  cat "$(asdf_dir)/help.txt"
}
asdf_help() {
  printf "version: %s\\n\\n" "$(asdf_version)"
  cat "$(asdf_dir)/libexec/help.txt"
}

and then editing libexec/lib/utils.bash

adding libexec to the version.txt path

asdf_version() {
  local version git_rev
  version="v$(cat "$(asdf_dir)/version.txt")"
  if [ -d "$(asdf_dir)/.git" ]; then
    git_rev="$(git --git-dir "$(asdf_dir)/.git" rev-parse --short HEAD)"
    printf "%s-%s\\n" "$version" "$git_rev"
  else
    printf "%s\\n" "$version"
  fi
}
asdf_version() {
  local version git_rev
  version="v$(cat "$(asdf_dir)/libexec/version.txt")"
  if [ -d "$(asdf_dir)/.git" ]; then
    git_rev="$(git --git-dir "$(asdf_dir)/.git" rev-parse --short HEAD)"
    printf "%s-%s\\n" "$version" "$git_rev"
  else
    printf "%s\\n" "$version"
  fi
}

Steps to Reproduce

  1. brew install asdf
  2. source /home/linuxbrew/.linuxbrew/opt/asdf/libexec/asdf.fish
  3. asdf

Expected Behaviour

it should execute the asdf command

Actual Behaviour

returns this error

/home/linuxbrew/.linuxbrew/Cellar/asdf/0.10.1/libexec/bin/asdf: line 82: /home/linuxbrew/.linuxbrew/opt/asdf/lib/commands/command-help.bash: No such file or directory

Environment

(asdf isn't working)

asdf plugins affected (if relevant)

(none)

nathanpalmer avatar May 19 '22 13:05 nathanpalmer

I just installed the latest version via homebrew as well and am getting a similar error:

/usr/local/Cellar/asdf/0.10.0/libexec is not a directory
/usr/local/Cellar/asdf/0.10.1/libexec/asdf.sh:.:35: no such file or directory: /usr/local/Cellar/asdf/0.10.0/libexec/lib/asdf.sh

In my setup, I am using zsh, and the error above happens upon sourcing my .zshrc file. I have tried reinstalling asdf, removing all existing shims, etc, but no luck. 😞

derekhubbard avatar May 19 '22 14:05 derekhubbard

Looks like my desktop on macOS just upgraded to 0.10.1 this morning

homebrew install
==> Upgrading asdf
  0.9.0 -> 0.10.1

==> Installing dependencies for asdf: coreutils and unixodbc
==> Installing asdf dependency: coreutils
==> Pouring coreutils--9.1.arm64_monterey.bottle.tar.gz
🍺  /opt/homebrew/Cellar/coreutils/9.1: 480 files, 13.3MB
==> Installing asdf dependency: unixodbc
==> Pouring unixodbc--2.3.11.arm64_monterey.bottle.tar.gz
🍺  /opt/homebrew/Cellar/unixodbc/2.3.11: 48 files, 2.3MB
==> Installing asdf
==> Pouring asdf--0.10.1.all.bottle.tar.gz
==> Caveats
To use asdf, add the following line to your ~/.config/fish/config.fish:
  source /opt/homebrew/opt/asdf/libexec/asdf.fish

Restart your terminal for the settings to take effect.

fish completions have been installed to:
  /opt/homebrew/share/fish/vendor_completions.d
==> Summary
🍺  /opt/homebrew/Cellar/asdf/0.10.1: 168 files, 714.3KB
==> Running `brew cleanup asdf`...
Removing: /opt/homebrew/Cellar/asdf/0.9.0... (150 files, 627.4KB)

and now i'm getting the same error

Unknown command: `asdf `
/opt/homebrew/Cellar/asdf/0.10.1/libexec/bin/asdf: line 82: /opt/homebrew/opt/asdf/lib/commands/command-help.bash: No such file or directory

nathanpalmer avatar May 21 '22 13:05 nathanpalmer

Thanks for reporting. Is there anyway for you to downgrade to version 0.10.0 with Brew to verify that it is in fact due to a change in version 0.10.1? Thanks!

For reference, here is the list of changes in 0.10.1 - https://github.com/asdf-vm/asdf/blob/master/CHANGELOG.md#0101-2022-05-17 I really don't know what change introduced a problem - and with the git installation method I have not observed a problem. don't invoke asdf inside asdf commands (#1208) (27f7ef7) is the only significant change, but I wouldn't expect it to introduce this problem.

Stratus3D avatar May 23 '22 01:05 Stratus3D

In macOS environment, it seems like there might be some kind of version number mismatch internally; after upgradeing to 0.10.1, sourcing asdf.fish resulted in an error like this:

.: Error encountered while sourcing file '/opt/homebrew/Cellar/asdf/0.10.0/libexec/lib/asdf.fish':                                  
.: No such file or directory

Setting ASDF_DIR to the correct path before sourcing asdf.fish worked for me as a temporary workaround.

# ~/.config/fish/config.fish

set -x ASDF_DIR '/opt/homebrew/Cellar/asdf/0.10.1/libexec'
source /opt/homebrew/opt/asdf/libexec/asdf.fish

yuhr avatar May 23 '22 06:05 yuhr

I don't think there is a way to downgrade using homebrew, unless they are setup in a versioned way. Typically I'd try to install a lower version like this brew install [email protected] but that recipe doesn't exist.

My previous config.fish was set to do this

set -x ASDF_DIR (brew --prefix asdf)
source $ASDF_DIR/asdf.fish

Looks like according to the latest instructions that that might be outdated. I don't have my homebrew installed anymore to check though. I just changed my installation to install from git instead of homebrew and it seemed to work well.

nathanpalmer avatar May 23 '22 11:05 nathanpalmer

For the record, I run brew edit asdf, then changed the version in the brew recipe, then run brew install asdf --build-from-source --verbose --debug, then got a error about the checksum, then edited the checksum too and retried and hopefully I managed to properly install 0.9.0 and 0.10.0 by doing this. But I still got the same error.

I didn't dig further and changed my installation too to install from git and it worked well.

deivid-rodriguez avatar May 23 '22 13:05 deivid-rodriguez

If anyone is familiar with Homebrew the formula is here - https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/asdf.rb. I don't see any obvious issues there.

Stratus3D avatar May 23 '22 13:05 Stratus3D

I've found a temporary workaround:

  1. Manually delete all shims: rm -rf ~/.asdf/shims
  2. Reshim them from scratch: asdf reshim

@Stratus3D I haven't found the commit that caused it, but the issue stems from "hard-generating" the path to asdf installation and the path itself contains version number. For example:

#!/usr/bin/env bash
# asdf-plugin: erlang 24.2.1
exec /opt/homebrew/Cellar/asdf/0.9.0/libexec/bin/asdf exec "erl" "$@" # asdf_allow: ' asdf '

So whenever you upgrade asdf from brew, 0.9.0 dir just disappears and asdf fails to find it.

If I understand the logic in reshim.bash, this part right here doesn't check if the directory is still valid:

https://github.com/asdf-vm/asdf/blob/788ccab5971cb828cf25364b0df5ed6f5e9e713d/lib/commands/reshim.bash#L91-L101=

One way to fix this is to switch from generating fixed prefix (/opt/homebrew/Cellar/asdf/0.10.1/ in the example above) to dynamically find the directory. But probably it's something Homebrew formula should fix? 🤔

jrogov avatar May 24 '22 12:05 jrogov

@Stratus3D wouldn't it makes sense to change $(asdf_dir) to \${ASDF_DIR} on line below so it would pick correct directory dynamically?

https://github.com/asdf-vm/asdf/blob/788ccab5971cb828cf25364b0df5ed6f5e9e713d/lib/commands/reshim.bash#L100

We still need to forcefully reshim all shims with new release for this to take place.

jrogov avatar May 24 '22 12:05 jrogov

I got the same issue, seems like shims are not updated properly when using brew since the versions is captured in the path.

Using 0.10.2 the shim was still pointing to non-existent 0.9.0.

~/asdf/shims/java: line 7: /usr/local/Cellar/asdf/0.9.0/libexec/bin/asdf: No such file or directory

Running asdf reshim java <version> does nothing to the actual exec command.

➜  spring-app asdf reshim java corretto-17.0.3.6.1
➜  spring-app cat ~/.asdf/shims/java
#!/usr/bin/env bash
# asdf-plugin: java corretto-11.0.14.10.1
# asdf-plugin: java corretto-8.322.06.1
# asdf-plugin: java corretto-11.0.15.9.1
# asdf-plugin: java corretto-17.0.3.6.1
# asdf-plugin: java graalvm-22.1.0+java17
exec /usr/local/Cellar/asdf/0.9.0/libexec/bin/asdf exec "java" "$@"

To fix I had to rm ~/.asdf/shims/<plugin> then reshim asdf reshim java <version> then it's fixed.

➜  spring-app rm ~/.asdf/shims/java
➜  spring-app asdf reshim java corretto-17.0.3.6.1
➜  spring-app cat ~/.asdf/shims/java
#!/usr/bin/env bash
# asdf-plugin: java corretto-17.0.3.6.1
exec /usr/local/Cellar/asdf/0.10.2/libexec/bin/asdf exec "java" "$@" # asdf_allow: ' asdf '
java -version
openjdk version "17.0.3" 2022-04-19 LTS
OpenJDK Runtime Environment Corretto-17.0.3.6.1 (build 17.0.3+6-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.3.6.1 (build 17.0.3+6-LTS, mixed mode, sharing)

kevdowney avatar Jun 11 '22 00:06 kevdowney

I encountered the similar error when I updated to 0.10.2 via Homebrew. However, in my case, starting a new shell solved the problem.

/opt/homebrew/Cellar/asdf/0.10.2/libexec/bin/asdf: line 82: /opt/homebrew/Cellar/asdf/0.10.1/libexec/lib/commands/command-help.bash: No such file or directory

negibouze avatar Jun 13 '22 07:06 negibouze

I'm having the same issue on OS X and running rm -rf ~/.asdf/shims && asdf reshim worked for me.

spacecowb0y avatar Jun 18 '22 08:06 spacecowb0y

This thread seems related to #531

Still awaiting feedback in potential fix PR #1236

jthegedus avatar Jun 21 '22 03:06 jthegedus

Dupe of https://github.com/asdf-vm/asdf/issues/1115. Think they're trying to use that as the main issue.

dylan-chong avatar Jul 25 '22 10:07 dylan-chong

It's seems a error with the new versions of asdf, I had a similar error:

/usr/local/Cellar/asdf/0.10.2/libexec/bin/asdf: line 82: /usr/local/Cellar/asdf/0.9.0/libexec/lib/commands/command-help.bash: No such file or directory

And solved by adding this to my ~/.zshrc file (you can just change for the version you need):

export ASDF_DIR=/usr/local/Cellar/asdf/0.10.2/libexec

And then:

asdf reshim

f2acode avatar Aug 09 '22 23:08 f2acode

In fish shell, remove $ASDF_DIR.

set -eg ASDF_DIR

1natsu172 avatar Sep 15 '23 17:09 1natsu172