error while installing go from source

huangapple go评论97阅读模式
英文:

error while installing go from source

问题

我正在尝试从源代码安装Go语言。

我按照以下步骤进行操作:

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.

你有什么想法,我该如何解决这个问题?我只需要设置环境变量,还是需要进行其他安装?

英文:

i am trying to install go from source

i follow this steps

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

cd src
./all.bash

now it gives me the error saying

##### 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.

any idea how can i fix this do i just need to set env variable or any other installation is needed ?

答案1

得分: 6

你需要安装 Go 1.4 或更新版本才能构建最新的 Go 发行版。构建脚本默认使用某个路径,但如果该路径不存在,你需要设置 GOROOT_BOOTSTRAP 环境变量,将其指向之前已安装的 Go 版本。

英文:

You need to have an installed Go version 1.4 or newer to build the recent Go releases. The build script defaults to some path but if it's not there you need to set GOROOT_BOOTSTRAP environment variable to point to a previous working Go installation.

答案2

得分: 4

Go是用Go语言编写的(从1.5版本开始),所以您首先需要安装Go1.4。只需获取Go版本管理器并运行以下命令:

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

另一种方法是安装gcc的Go前端:

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

英文:

Go is written in Go (starting from version 1.5) so you have to install Go1.4 first. Just get Go Version Manager and run:

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

Another approach is about to install gcc go frontend:

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

答案3

得分: 0

如果您没有使用gvm并且在Linux上,您的go二进制文件大多安装在/usr/local/go/bin/go路径下。您需要将/usr/local/go设置为您的GOROOT_BOOTSTRAP,方法如下:

$ export GOROOT_BOOTSTRAP=/usr/local/go
英文:

If you are not using gvm and are on Linux, your go binary is mostly installed at /usr/local/go/bin/go. You need to set /usr/local/go as your GOROOT_BOOTSTRAP by:

$ export GOROOT_BOOTSTRAP=/usr/local/go

答案4

得分: 0

以下是翻译好的内容:

如果您之前没有从源代码构建过(版本解析将失败),以下内容将无法正常工作。不幸的是,它也不适用于Windows(除非您使用的是wsl/cygwin/msys等)。如果您有旧版本的源代码,您可以使用以下zsh/bash(?)函数:

# 通过将目录的内容递归地复制到一个相似名称的空目录中来创建目录的备份
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)                              # 访问当前go安装的根目录
bckp                                             # 备份
git stash                                        # 将您所做的但不想提交的更改保存在一个安全的位置
git pull                                         # 获取远程提交
git stash pop                                    # 恢复您的更改
cd src                                           # 进入golang源文件和安装脚本目录
export GOROOT_BOOTSTRAP=$(go env GOROOT)-bckp    # 使环境变量在其他shell中可访问
chmod +x ./all.bash                              # 设置安装/构建脚本的权限以便执行
./all.bash                                       # 执行安装/构建脚本
cd ../bin && sudo ln -f $PWD/go /usr/bin/go      # 创建一个全局可访问的链接到新的二进制文件,感觉这是不必要的,但在我执行此操作之前无法使用新的二进制文件

或者,如果您已经获取了要包含的提交并弹出了您的更改:

cd $(go env GOROOT)                                      # 访问当前go安装的根目录
bckp                                                     # 备份
cd ../go-bckp                                            # 进入备份目录
git stash                                                # 将您所做的但不想提交的更改保存在一个安全的位置
git checkout $(go version | cut -d- -f2 | cut -d" " -f1) # 解析版本信息并恢复旧的代码库
git stash pop                                            # 恢复您的更改
cd ../go/src                                             # 进入golang源文件和安装脚本目录
export GOROOT_BOOTSTRAP=$(go env GOROOT)-bckp            # 使环境变量在其他shell中可访问
chmod +x ./all.bash                                      # 设置安装/构建脚本的权限以便执行
./all.bash                                               # 执行安装/构建脚本
cd ../bin && sudo ln -f $PWD/go /usr/bin/go              # 创建一个全局可访问的链接到新的二进制文件,感觉这是不必要的,但在我执行此操作之前无法使用新的二进制文件

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

cd $(go env GOROOT)                             # 访问当前go安装的根目录
bckp                                            # 备份
cd src                                          # 进入golang源文件和安装脚本目录
export GOROOT_BOOTSTRAP=$(go env GOROOT)-bckp   # 使环境变量在其他shell中可访问
chmod +x ./all.bash                             # 设置安装/构建脚本的权限以便执行
./all.bash                                      # 执行安装/构建脚本
cd ../bin && sudo ln -f $PWD/go /usr/bin/go     # 创建一个全局可访问的链接到新的二进制文件,感觉这是不必要的,但在我执行此操作之前无法使用新的二进制文件
英文:

The following won't work if you haven't previously built from source (the version parsing will fail). Unfortunately it also won't work for windows (unless you're in wsl/cygwin/msys et cetera).
If you have the source for an older version you may want to use the following zsh/bash(?) function

# 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"
}

then do one, or some combination, of the following

if you have unstashed changes you want to commit:

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

or, if you've already pulled the commits you wish to include and popped your changes:

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

or if you haven't made any changes:

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.

huangapple
  • 本文由 发表于 2016年4月18日 16:12:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/36688577.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定