How to get asdf's version to be the version
Asked Answered
S

5

14

Explained in terminal, I have installed a version of nodejs using asdf, but the terminal only sees the other version:

> asdf list
nodejs
  12.18.3

> nodejs --version
v8.10.0

> asdf global nodejs 12.18.3 

> nodejs --version          
v8.10.0

Have added the following to the top of .zshrc

. $HOME/.asdf/asdf.sh
export PATH=$HOME/.asdf/asdf.sh:$PATH

Have reloaded .zshrc

> source ~/.zshrc

There are no local files which are setting the local version to 8.10.0.

How do I get nodejs --version to give me the version that asdf acknowledges as the global version?

Subchloride answered 24/9, 2020 at 10:54 Comment(5)
did you install node using the asdf cli, as in asdf install nodejs 12.18.3?Irvingirwin
No, I used asdf install and the .tool-versions file has the nodejs version in it. Does that make a difference?Subchloride
It may as well - I am going blindly on what you have outlined in the OQ. And the .tool-versions file is in that directory with global defaults sets as $HOME/.tool-versions?Irvingirwin
What does type -a nodejs return for you? It sounds like you've got your system node taking precedence over everything managed by asdf. The asdf directories need to come first in your $PATH.Hensel
it says nodejs is /usr/bin/nodejs three times. When I do echo $PATH I get /usr/local/opt/[email protected]/bin:/home/joe/.asdf/shims:/home/joe/.asdf/bin: etc, so asdf is firstSubchloride
S
11

I had this problem on both Ubuntu 18.04 and Mac 10.15.7. There were several issues.

Installing asdf with brew (mac) does not install it properly - asdf.sh is missing. The docs suggest installing with git, which works.

As stated in the docs, the running of asdf.sh (grey box below) needs to be at the BOTTOM of .zshrc (or equivalent profile setting file, such as .bash_profile etc). It adds things to the start of the $PATH.

. $HOME/.asdf/asdf.sh

Naturally you need to run source .zshrc after modifying it so the terminal reloads the changes. This should result in changing your $PATH, so when you run echo $PATH you should have something that starts with:

/Users/homersimpson/.asdf/shims:/Users/homersimpson/.asdf/bin:/usr/local/opt/[email protected]/bin: ...other things separated by ':'

which node should give something like /Users/homersimpson/.asdf/shims/node. It is the shims for asdf being at the start of your path which make asdf's version be the version your system uses.

Subchloride answered 2/10, 2020 at 10:49 Comment(0)
T
3

If you want to install asdf with homebrew and zsh use this:

echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc

This adds the asdf.sh properly to the .zshrc file.

Read about it here

Termite answered 9/2, 2022 at 4:56 Comment(0)
V
1

I'm having the same issue, and I noticed that it seems to happen because asdf doesn't seem to know about a version of Ruby (2.6.3) I installed via asdf today. It recommends I use one of my three previous versions of Ruby:

james@James-Precision-5520:~/Git/elixirschool$ asdf current elixir 1.9.0-otp-22 (set by /home/james/.tool-versions) erlang 22.0.7 (set by /home/james/.tool-versions) ruby 2.6.3 (set by /home/james/.tool-versions) james@James-Precision-5520:~/Git/elixirschool$ jekyll asdf: No version set for command jekyll you might want to add one of the following in your .tool-versions file:

ruby 2.3.7 ruby 2.4.3 ruby 2.5.1 james@James-Precision-5520:~/Git/elixirschool$ ls ~/.asdf/installs/ruby 2.3.7 2.4.3 2.5.1 2.6.3 james@James-Precision-5520:~/Git/elixirschool$ asdf list ruby 2.3.7 2.4.3 2.5.1 2.6.3 When I changed my .tool-versions to point at one of the other three (older) Ruby installs, it started working.

Voussoir answered 28/7, 2021 at 17:6 Comment(0)
T
0

If you're already sourcing asdf in your zshrc, then this can be fixed by running:

asdf install TOOLCHAIN VERSION

and then running the global command again:

asdf global TOOLCHAIN VERSION

it seems I either neither ran the install before or somehow it got removed either by updating asdf or something else

Thrombin answered 1/7, 2023 at 10:38 Comment(0)
G
-1

If you installed node with Homebrew then you'll probably see something like this when you run which node which tells you the brew version is being used:

/opt/homebrew/bin/node

If you remove node from brew by running brew uninstall node then which node will likely flip over to the asdf version and you'll see something like:

/Users/you/.asdf/shims/node

Also, since you're using ZSH it's easiest to just use the asdf plugin like plugins=(asdf) in your .zshrc: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/asdf

Gravettian answered 27/2 at 18:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.