moovweb / gvm

Go Version Manager
http://github.com/moovweb/gvm
MIT License
9.87k stars 520 forks source link

install gvm lead to cd commad failed #439

Open sheepcat opened 10 months ago

sheepcat commented 10 months ago

[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) [root@localhost ~]# uname -a Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux [root@localhost ~]# rpm -qa |grep bash bash-4.2.46-34.el7.x86_64

i install gvm by this way : bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)

after installd, i logout and relogin , found cd cmd failed: [root@localhost ~]# pwd /root [root@localhost ~]# cd / [root@localhost ~]# pwd /root

when i delete the dir, it recoverd: rm -rf /root/.gvm/

goFrendiAsgard commented 10 months ago

I got a similar issue.

Can you please confirm the value of your $PATH before and after installing gvm?

echo $PATH

In my case, I have a PATH containing space that accidentally replaced by :

https://twitter.com/gofrendiasgard/status/1695596852127941055

codingcn commented 10 months ago

same issues

/home/chris/.gvm/bin:/home/chris/.config/nvm/versions/node/v14.21.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/sbin:/usr/sbin:/usr/local/go/bin:/home/chris/go/bin
chris@chris-PC:~$ type cd
cd 是函数
cd () 
{ 
    if __gvm_is_function __gvm_oldcd; then
        __gvm_oldcd $*;
    fi;
    local dot_go_version dot_go_pkgset rslt;
    local defaults_go_name defaults_go_pkgset;
    local defaults_resolved=false;
    local defaults_hash;
    defaults_hash=();
    if [[ "$GVM_ROOT" == "" ]]; then
        display_error "GVM_ROOT not set. Please source \$GVM_ROOT/scripts/gvm";
        return $?;
    fi;
    [[ "${GVM_DEBUG}" -eq 1 ]] && echo "Resolving defaults...";
    defaults_hash=($(__gvm_read_environment_file "${GVM_ROOT}/environments/default"));
    if [[ $? -eq 0 ]]; then
        defaults_resolved=true;
    else
        [[ "${GVM_DEBUG}" -eq 1 ]] && echo "Can't find default environment. Falling back to system.";
        defaults_hash=($(__gvm_read_environment_file "${GVM_ROOT}/environments/system"));
        if [[ $? -eq 0 ]]; then
            defaults_resolved=true;
        else
            [[ "${GVM_DEBUG}" -eq 1 ]] && echo "Can't find system environment.";
        fi;
    fi;
    if [[ "${defaults_resolved}" == false ]]; then
        [[ "${GVM_DEBUG}" -eq 1 ]] && echo "Resolving fallback go version and pkgset from all available.";
        local fallback_go_version="$(__gvm_resolve_fallback_version)";
        local fallback_go_pkgset="$(__gvm_resolve_fallback_pkgset "${fallback_go_version}")";
        [[ "${GVM_DEBUG}" -eq 1 ]] && echo "=======================================";
        [[ "${GVM_DEBUG}" -eq 1 ]] && echo "fallback_go_version => $fallback_go_version";
        [[ "${GVM_DEBUG}" -eq 1 ]] && echo "fallback_go_pkgset => $fallback_go_pkgset";
        [[ "${GVM_DEBUG}" -eq 1 ]] && echo "=======================================";
        defaults_hash=($(setValueForKeyFakeAssocArray "gvm_go_name" "${fallback_go_version}" "${defaults_hash[*]}"));
        defaults_hash=($(setValueForKeyFakeAssocArray "gvm_pkgset_name" "${fallback_go_pkgset}" "${defaults_hash[*]}"));
        unset fallback_go_version;
        unset fallback_go_pkgset;
        defaults_resolved=true;
    fi;
    defaults_go_name="$(valueForKeyFakeAssocArray "gvm_go_name" "${defaults_hash[*]}")";
    defaults_go_pkgset="$(valueForKeyFakeAssocArray "gvm_pkgset_name" "${defaults_hash[*]}")";
    [[ "${GVM_DEBUG}" -eq 1 ]] && echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
    [[ "${GVM_DEBUG}" -eq 1 ]] && echo "defaults_go_name => $defaults_go_name";
    [[ "${GVM_DEBUG}" -eq 1 ]] && echo "defaults_go_pkgset => $defaults_go_pkgset";
    [[ "${GVM_DEBUG}" -eq 1 ]] && echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
    if [[ "${GVM_DEBUG}" -eq 1 ]]; then
        echo "Resolved default go: ${defaults_go_name:-[EMPTY]}";
        echo "Resolved default pkgset: ${defaults_go_pkgset:-[EMPTY]}";
    fi;
    dot_go_version="$(__gvmp_find_closest_dot_go_version)";
    rslt=$?;
    [[ "${GVM_DEBUG}" -eq 1 ]] && echo "---------------------------------------";
    [[ "${GVM_DEBUG}" -eq 1 ]] && echo "dot_go_version => $dot_go_version";
    [[ "${GVM_DEBUG}" -eq 1 ]] && echo "defaults_go_name => $defaults_go_name";
    [[ "${GVM_DEBUG}" -eq 1 ]] && echo "---------------------------------------";
    if [[ $rslt -eq 0 ]]; then
        [[ "${GVM_DEBUG}" -eq 1 ]] && echo "Found dot_go_version: ${dot_go_version}";
        local use_goversion="$(__gvmp_read_dot_go_version "${dot_go_version}")";
        [[ "${GVM_DEBUG}" -eq 1 ]] && echo "Switching to: ${use_goversion}";
        gvm use "${use_goversion}" || return 1;
        unset use_goversion;
    else
        if [[ -n "${defaults_go_name}" ]]; then
            [[ "${GVM_DEBUG}" -eq 1 ]] && echo "No .go-version found. Using system or default go.";
        else
            if [[ "${GVM_DEBUG}" -eq 1 ]]; then
                echo "No fallback go version could be found.";
                if [[ ! -d "$GVM_ROOT/archive/go" ]]; then
                    echo "$(locale_text_for_key "go_install_prompt")";
                fi;
            fi;
            return 0;
        fi;
    fi;
    dot_go_pkgset="$(__gvmp_find_closest_dot_go_pkgset)";
    rslt=$?;
    [[ "${GVM_DEBUG}" -eq 1 ]] && echo "--------------------------------";
    [[ "${GVM_DEBUG}" -eq 1 ]] && echo "dot_go_pkgset => $dot_go_pkgset";
    [[ "${GVM_DEBUG}" -eq 1 ]] && echo "--------------------------------";
    if [[ $rslt -eq 0 ]]; then
        [[ "${GVM_DEBUG}" -eq 1 ]] && echo "Found .go-pkgset: ${dot_go_pkgset}";
        local use_gopkgset="$(__gvmp_read_dot_go_pkgset "${dot_go_pkgset}")";
        [[ "${GVM_DEBUG}" -eq 1 ]] && echo "Switching to: ${use_gopkgset}";
        gvm pkgset use "${use_gopkgset}" || return 1;
        unset use_gopkgset;
    else
        if [[ -n "${defaults_go_pkgset}" ]]; then
            [[ "${GVM_DEBUG}" -eq 1 ]] && echo "No .go-pkgset found. Using system or default pkgset.";
            [[ "${GVM_DEBUG}" -eq 1 ]] && echo "----------    defaults_go_pkgset => $defaults_go_pkgset     ----------";
        else
            [[ "${GVM_DEBUG}" -eq 1 ]] && echo "No fallback pkgset could be found.";
        fi;
    fi;
    return 0
}
clanaid commented 10 months ago

how to fix it?

ankitcharolia commented 10 months ago

@clanaid @codingcn @sheepcat : Kindly try out this one. this supports bash and zsh both shells : https://github.com/ankitcharolia/goenv