$GOROOT_BOOTSTRAP variable not found if all.bash is run with sudo

1,206 views
Skip to first unread message

xMudrii

unread,
Dec 10, 2016, 2:19:09 PM12/10/16
to golang-nuts
Hi,

I have downloaded Go 1.4 binaries and moved it to `/usr/local/go1.4` for example.
Also I defined GOROOT_BOOTSTRAP variable in my users `.profile` file:
`export GOROOT_BOOTSTRAP=/usr/local/go1.4`

I sourced file and if I run echo $GOROOT_BOOTSTRAP, it'll work correctly.

When I run `bash all.bash` it'll detect variable correctly:
##### Building Go bootstrap tool.
cmd
/dist


##### Building Go toolchain using /usr/local/go1.4.


Now example will not work, because if my user doesn't have write privileges in folder with
go1.4, it'll error. That's normal, so in cases like that I run script with root privileges:
`sudo bash all.bash`

But it doesn't detect variable:
##### Building Go bootstrap tool.
cmd
/dist


ERROR
: Cannot find /home/vtest/go1.4/bin/go.
Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.


It is trying to find default location instead one set in profile.

I added it to roots `~/.profile` but no avail. Also tried `~/.bashrc` on both users
and it doesn't work. (I used source on files).

Some details for reference:
lsb_release -a:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.1 LTS
Release: 16.04
Codename: xenial
uname -a:
Linux vtest 4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux


Is it possible to run `all.bash` with sudo or it's not recommended?
Sometimes when I place sources in `/usr/local` (because of GOROOT for example), I need to run `all.bash` with sudo.
Same applies if I only place Go 1.4 there.

Jan Mercl

unread,
Dec 10, 2016, 2:23:17 PM12/10/16
to xMudrii, golang-nuts



On Sat, Dec 10, 2016 at 8:18 PM xMudrii <mudrin...@gmail.com> wrote:

> `sudo bash all.bash`

$ sudo all.bash

--

-j

mudrin...@gmail.com

unread,
Dec 10, 2016, 2:28:14 PM12/10/16
to golang-nuts, mudrin...@gmail.com
`sudo all.bash`
sudo: all.bash: command not found

Same for `sudo ./all.bash`.

But I found out that `sudo -E bash ./all.bash` is working. So I think it's solved now.

Dmitri Goutnik

unread,
Dec 10, 2016, 2:29:17 PM12/10/16
to xMudrii, golang-nuts
sudo sanitizes environment, you need to either pass -E option or add GOROOT_BOOTSTRAP to env_keep in /etc/sudoers:

Defaults env_keep += "GOROOT_BOOTSTRAP"

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mudrin...@gmail.com

unread,
Dec 10, 2016, 2:30:25 PM12/10/16
to golang-nuts, mudrin...@gmail.com
Thanks! It's working flawless with -E flag. =)
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
Message has been deleted
Message has been deleted

Simon Ritchie

unread,
May 28, 2017, 5:20:53 AM5/28/17
to golang-nuts
Your original problem was that your user didn't own the directory /usr/local/go1.4 or it contents.   I presume that you named it like that so that you could keep different versions of Go in different directories.

I do the same, but I did a little more work at the start, to save a lot of time later.  Do the following just once:

Create /usr/local/golang owned by your ordinary user - mine is simon, in group simon

- $ sudo mkdir /usr/local/golang

- $ sudo chown simon /usr/local/golang    # use "chown -R" (capital R) if the directory already exists

- $ sudo chgrp simon /usr/local/golang      # ditto

Once that's done, the user simon owns /usr/local/golang and anything in it, so that user can create Go distributions in that directory.

As your ordinary user, create /usr/local/golang/1.4 containing Go 1.4.    Build it:

$ export GOROOT_FINAL=/usr/local/go

(The first time you do this, that directory may not exist, but that's OK.)

$ cd  /usr/local/golang/1.4

$ ./all.bash

This produces /usr/local/golang/1.4/go containing a Go distribution that expects to be stored in /usr/local/go.

Create a file called /usr/local/go which is a soft link to /usr/local/golang/1.4/go:

$ sudo ln -s  /usr/local/golang/1.4/go  /usr/local/go

$ ls -l /usr/local/go
lrwxrwxrwx 1 root root 24 May 24  2017 /usr/local/go -> /usr/local/golang/1.4/go


You now have a directory /usr/local/go containing a working Go distribution.


Put /usr/local/go/bin in your path.

You only have to do all that once.  From now on, to upgrade to the latest version of Go, do this:

Create a directory in /usr/local/golang and put the latest distribution in there.  For version 1.8.3., create /usr/local/golang/1.8.3.

$ export GOROOT_FINAL=/usr/local/go

$ cd  /usr/local/golang/1.8.3

$ ./all.bash

This produces /usr/local/golang/1.8.3/go containing a Go distribution that expects to be stored in /usr/local/go.

Remove the soft link:

$ sudo rm /usr/local/go

and create a new one:

$ sudo ln -s /usr/local/golang/1.8.3/go /usr/local/go

(Don't do that too early in the process - you need the link to the old distribution to build the new distribution.)

This procedure has a number of advantages - your current version of Go is always called /usr/local/go, you don't have to run many commands as root and the process of upgrading to the next version is reasonably simple.

Reply all
Reply to author
Forward
0 new messages