13

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
  • Do what "Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4" tells you to do. Commented Apr 18, 2016 at 8:50

4 Answers 4

8

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.

Sign up to request clarification or add additional context in comments.

4 Comments

as a user that's new to this, this is completely absurd; why would i need to have 'go' installed in order to install 'go'...??!! and why does the official website not mention this in the installation/downloads page?
@EliranMalka I assume you've been leaving the same angry comment on every C compiler for the past 40+ years. Also, you might want to understand the difference between "build" and "install".
hmm actually that's a first for me. guess i never needed to compile C before. still absurd tho. by "install" i just meant install on my system. not sure why "build" should be relevant here - all i wanted was to have 'go' on my OS so i can run a tool that depends on it..
i'd love to have a simple way to just install the latest version of go, is what i'm saying. currently, there doesn't seem to be any.
4

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

2 Comments

on raspberry i have this error after running sudo update-alternatives --set go /usr/bin/go-5 please help to understand: update-alternatives: error: no alternatives for go
please look at this post, you probably have to install your alternative before setting it
0

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.