Emily
Emily

Reputation: 2331

Installing asdf: Path doesn't seem to be recognized?

I'm trying to install asdf on Debian 11. After install, I still get this error:

bash: asdf: command not found

Suspect: I'm sourcing something incorrectly.

Here's the script I'm using to install with:

#!/bin/bash

# Install prerequisites
sudo apt-get update
sudo apt-get install -y curl git

export https_proxy=127.0.0.1:8082

    # Install asdf
    git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.11.3
    
    # Add asdf to the bash shell
    echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.bashrc
    echo -e '\n. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc
    
    # Add asdf to the git shell
    echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.gitbashrc
    echo -e '\n. $HOME/.asdf/completions/asdf.bash' >> ~/.gitbashrc
    
    # Activate asdf in the current shell
    source ~/.bashrc
    source ~/.gitbashrc

I've tried adding manually to .bashrc & .gitbashrc. Here's what .bashrc & .gitbashrc look like:

.bashrc

export PATH="$PATH:$HOME/.asdf/bin"
. "$HOME/.asdf/asdf.sh"
. "$HOME/.asdf/completions/asdf.bash"

.gitbashrc

export PATH="$PATH:$HOME/.asdf/bin"
. "$HOME/.asdf/asdf.sh"
. "$HOME/.asdf/completions/asdf.bash"

I've tried with and without the export path command.

I've reloaded the terminal, but every time I try to call asdf I get something like this:

user@user:~$ asdf plugin add erlang https://github.com/asdf-vm/asdf-erlang.git
bash: asdf: command not found

/.asdf folder exists and has the files in it. For some reason the shell just isn't finding it. Any ideas?

Upvotes: 3

Views: 5391

Answers (2)

Jonathan
Jonathan

Reputation: 894

The problem is that you are relying on .bashrc in a non-interactive environment (in a script). This usually doesn't work because on a standad ubuntu installation bashrc has the following lines at the start:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

Therefore the line . $HOME/.asdf/asdf.sh is not executed inside the bash script. You simply could add this line:

. "$HOME/.asdf/asdf.sh"

directly to the script instead of first adding it to .bashrc.

Upvotes: 1

hyperupcall
hyperupcall

Reputation: 973

First of all, I would recommend removing the path-prepending you do:

export PATH="$PATH:$HOME/.asdf/bin"

In the case of asdf, it doesn't do anything because no executables are located in ~/.asdf/bin. When you source ~/.asdf/asdf.sh, it already prepends the necessary stuff to the path.

To debug this, I would recommend trying the following

  • Run set -x in any scripts or interactively before sourcing ~/.asdf/asdf.sh to ensure it is actually doing so
  • Make sure that you are running bash and not dash (in the case of dash, the ~/.profile file is read instead of ~/.bashrc

Besides these tips, there isn't anything much I can do because it seems like some setup issue on your specific computer.

Upvotes: 0

Related Questions