How to get asdf's version to be the version

9.6k Views Asked by At

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?

5

There are 5 best solutions below

0
On BEST ANSWER

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.

0
On

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

0
On

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
On

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

0
On

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