从源安装go时出错

jq6vz3qz  于 2022-12-16  发布在  Go
关注(0)|答案(4)|浏览(253)

我正在尝试安装go from source
我遵循以下步骤

git clone https://go.googlesource.com/go
cd go
git checkout go1.6.1

cd src
./all.bash

现在它给了我一个错误

##### Building Go bootstrap tool.
cmd/dist
ERROR: Cannot find /root/go1.4/bin/go.
Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.

有什么想法我怎么能解决这个问题,我只需要设置env变量或任何其他安装是必要的吗?

irtuqstp

irtuqstp1#

你需要安装Go语言1.4版或更高版本来构建最新的Go语言版本,构建脚本默认为某个路径,但如果没有,你需要设置GOROOT_BOOTSTRAP环境变量来指向之前的Go语言安装。

zvokhttg

zvokhttg2#

Go语言是用Go语言编写的(从1.5版开始),所以你必须先安装Go1.4版,只需要打开Go语言版本管理器并运行:

$ gvm install go1.4 
$ gvm use go1.4 
$ export GOROOT_BOOTSTRAP=$GOROOT

另一种方法是安装gcc go frontend:

$ sudo apt-get install gccgo-5
$ sudo update-alternatives --set go /usr/bin/go-5
$ export GOROOT_BOOTSTRAP=/usr
lztngnrs

lztngnrs3#

如果你没有使用gvm,而是在Linux上,你的go二进制文件通常安装在/usr/local/go/bin/go上,你需要通过以下方式将/usr/local/go设置为你的GOROOT_BOOTSTRAP

$ export GOROOT_BOOTSTRAP=/usr/local/go
zpgglvta

zpgglvta4#

下面的***不会***工作如果你以前没有从源代码构建(版本解析将失败)。不幸的是,它也不会为windows工作(除非你在 * wsl/cygwin/msys * 等)。
如果您有旧版本的源代码,则可能需要使用以下zsh/bash(?)函数

# create a backup of a directory by recursively copying its contents into an empty one with a similar name
bckp () {
    old=$1 
    if [[ -z $1 ]]; then
        old="../$(basename "$(pwd)")" 
    fi
    new="$old-bckp" 
    [[ -d $new ]] && echo "already exists" && return 1
    cp -rf "$old/" "$new"
}

然后执行以下操作之一或组合
如果你有你想要提交的未隐藏的更改:

cd $(go env GOROOT)                              # visit the root directory of your current go installation
bckp                                             # back it up
git stash                                        # keep any changes you've made but do not want to commit in a safe place
git pull                                         # collect remote commits
git stash pop                                    # restore your changes
cd src                                           # go to the golang source files and installation scripts
export GOROOT_BOOTSTRAP=$(go env GOROOT)-bckp    # make the environment variable accessible from other shells
chmod +x ./all.bash                              # set the permissions of the installation/build script so that it can be executed
./all.bash                                       # execute the installation/build script
cd ../bin && sudo ln -f $PWD/go /usr/bin/go      # create a globablly accessible link to the new binary, feels like it should be unnecessary but I couldn't use the new binary until I did this

或者,如果你已经拉取了你想要包含的提交并弹出了你的修改:

cd $(go env GOROOT)                                      # visit the root directory of your current go installation
bckp                                                     # back it up
cd ../go-bckp                                            # enter the backup directory
git stash                                                # keep any changes you've made but do not want to commit in a safe place
git checkout $(go version | cut -d- -f2 | cut -d" " -f1) # parse version info and restore the old codebase
git stash pop                                            # restore your changes
cd ../go/src                                             # go to the golang source files and installation scripts
export GOROOT_BOOTSTRAP=$(go env GOROOT)-bckp            # make the environment variable accessible from other shells
chmod +x ./all.bash                                      # set the permissions of the installation/build script so that it can be executed
./all.bash                                               # execute the installation/build script
cd ../bin && sudo ln -f $PWD/go /usr/bin/go              # create a globablly accessible link to the new binary, feels like it should be unnecessary but I couldn't use the new binary until I did this

或者,如果您没有进行任何更改:

cd $(go env GOROOT)                             # visit the root directory of your current go installation
bckp                                            # back it up
cd src                                          # go to the golang source files and installation scripts
export GOROOT_BOOTSTRAP=$(go env GOROOT)-bckp   # make the environment variable accessible from other shells
chmod +x ./all.bash                             # set the permissions of the installation/build script so that it can be executed
./all.bash                                      # execute the installation/build script
cd ../bin && sudo ln -f $PWD/go /usr/bin/go     # create a globablly accessible link to the new binary, feels like it should be unnecessary but I couldn't use the new binary until I did this.

相关问题