13

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?

xxjjnn
  • 14,591
  • 19
  • 61
  • 94
  • did you install node using the asdf cli, as in `asdf install nodejs 12.18.3`? – rags2riches-prog Sep 24 '20 at 11:05
  • No, I used `asdf install` and the `.tool-versions` file has the nodejs version in it. Does that make a difference? – xxjjnn Sep 24 '20 at 11:07
  • 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`? – rags2riches-prog Sep 24 '20 at 11:21
  • 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`. – Stratus3D Sep 29 '20 at 15:37
  • it says `nodejs is /usr/bin/nodejs` three times. When I do `echo $PATH` I get `/usr/local/opt/qt@5.5/bin:/home/joe/.asdf/shims:/home/joe/.asdf/bin:` etc, so asdf is first – xxjjnn Oct 01 '20 at 18:33

4 Answers4

10

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/qt@5.5/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.

xxjjnn
  • 14,591
  • 19
  • 61
  • 94
2

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

Jason Cheladyn
  • 565
  • 1
  • 12
  • 24
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.

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

Sam Denty
  • 3,693
  • 3
  • 30
  • 43