Giter Club home page Giter Club logo

update-golang's Introduction

license Travis Build Status

update-golang

update-golang is a script to easily fetch and install new Golang releases with minimum system intrusion.

Table of Contents

Created by gh-md-toc

How it works

The script is based on official installation instructions from https://go.dev/doc/install.

This is the default behavior:

1. Search for the latest binary release in https://go.dev/dl/.

2. The script uses local system OS and ARCH to download the correct binary release. It is not harmful to run the script multiple times. Downloaded releases are kept as cache under '/usr/local'. You can erase them manually.

By default, the script only detects actual releases (not beta releases, not release candidates). However one can force any specific non-final release:

$ # force specific release candidate
$ sudo RELEASE=1.11rc1 ./update-golang.sh

3. The release is installed at '/usr/local/go'.

4. The path '/usr/local/go/bin' is added to PATH using '/etc/profile.d/golang_path.sh'.

5. Only if needed, GOROOT is properly setup, also using '/etc/profile.d/golang_path.sh'.

The script DOES NOT ever modify the GOPATH variable.

You can customize the behavior by setting environment variables (see Customization below).

Usage

git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh

Caution

Before running the script, make sure you have an untampered copy by verifying the SHA256 checksum.

$ wget -qO hash.txt https://raw.githubusercontent.com/udhos/update-golang/master/update-golang.sh.sha256
$ sha256sum -c hash.txt
update-golang.sh: OK

Remove

You can use the 'remove' option to undo update-golang.sh work:

$ sudo ./update-golang.sh remove

Declutter

You can use the '-declutter' option to prevent caching downloaded archives:

$ sudo ./update-golang.sh -declutter

Example

Sample session:

lab@ubu1:~$ go
The program 'go' can be found in the following packages:
 * golang-go
 * gccgo-go
Try: sudo apt install <selected package>
lab@ubu1:~$
lab@ubu1:~$ git clone https://github.com/udhos/update-golang
Cloning into 'update-golang'...
remote: Counting objects: 481, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 481 (delta 4), reused 9 (delta 2), pack-reused 468
Receiving objects: 100% (481/481), 70.22 KiB | 125.00 KiB/s, done.
Resolving deltas: 100% (248/248), done.
lab@ubu1:~$
lab@ubu1:~$ cd update-golang
lab@ubu1:~/update-golang$ sudo ./update-golang.sh
update-golang.sh: version 0.15
update-golang.sh: find_latest: found last release: 1.10.2
update-golang.sh: user: uid=0(root) gid=0(root) groups=0(root)
update-golang.sh: RELEASE_LIST=https://golang.org/doc/devel/release.html
update-golang.sh: SOURCE=https://storage.googleapis.com/golang
update-golang.sh: DESTINATION=/usr/local
update-golang.sh: RELEASE=1.10.2
update-golang.sh: OS=linux
update-golang.sh: ARCH_PROBE=uname -m
update-golang.sh: ARCH=amd64
update-golang.sh: PROFILED=/etc/profile.d/golang_path.sh
update-golang.sh: CACHE=/usr/local
update-golang.sh: GOPATH=
update-golang.sh: DEBUG=
update-golang.sh: will install golang go1.10.2.linux-amd64 as: /usr/local/go
update-golang.sh: https://storage.googleapis.com/golang/go1.10.2.linux-amd64.tar.gz is remote
update-golang.sh: no need to download - file cached: /usr/local/go1.10.2.linux-amd64.tar.gz
update-golang.sh: remove_old_link: not found symlink for old install
update-golang.sh: untar: tar -x -f /usr/local/go1.10.2.linux-amd64.tar.gz
update-golang.sh: path: removing old settings from: /etc/profile.d/golang_path.sh
update-golang.sh: path: issuing new /usr/local/go/bin to /etc/profile.d/golang_path.sh
update-golang.sh: path: issuing /home/lab/go/bin to /etc/profile.d/golang_path.sh
update-golang.sh: golang go1.10.2.linux-amd64 installed at: /usr/local/go
update-golang.sh: testing: /usr/local/go/bin/go version
update-golang.sh: go version go1.10.2 linux/amd64
update-golang.sh: /usr/local/go/bin/go version: SUCCESS
update-golang.sh: testing: /usr/local/go/bin/go run /tmp/hello-tmpv1bX1rQN.go
update-golang.sh: hello, world
update-golang.sh: /usr/local/go/bin/go run /tmp/hello-tmpv1bX1rQN.go: SUCCESS
update-golang.sh: cleanup: /tmp/tmp.tcNY25eXNl
lab@ubu1:~/update-golang$

Customization

These environment variables are available for customization:

RELEASE_LIST=https://golang.org/doc/devel/release.html ;# search for new releases from this url
SOURCE=https://storage.googleapis.com/golang           ;# download source location
DESTINATION=/usr/local                                 ;# install destination
RELEASE=1.8.3                                          ;# force golang release
OS=linux                                               ;# force os
ARCH_PROBE='uname -m'                                  ;# force arch detection command
ARCH=amd64                                             ;# force arch
PROFILED=/etc/profile.d/golang_path.sh                 ;# update PATH, optionally set GOROOT
CACHE=/usr/local                                       ;# cache downloads in this dir
GOPATH=                                                ;# use this GOPATH
DEBUG=                                                 ;# set to enable debug

Example:

$ sudo RELEASE=1.9beta1 ./update-golang.sh

Per-user Install

Default behavior is to install Golang globally for all system users.

However you can use the environment variables to point locations to your per-user home directory.

The per-user installation does not need root (sudo) privileges.

Example installing:

This example will install Golang under ~/golang for current user only.

$ mkdir ~/golang
$ DESTINATION=~/golang PROFILED=~/.bash_profile ./update-golang.sh

Example uninstalling:

To uninstall, make sure to provide the same env vars used for installing:

$ DESTINATION=~/golang PROFILED=~/.bash_profile ./update-golang.sh remove

END

update-golang's People

Contributors

adntgv avatar fouwels avatar nexweb avatar sergeyklay avatar tbobm avatar udhos avatar virgilwashere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

update-golang's Issues

unsudo can cause problems if profile writes to output

unsudo uses sudo -i which cause profile to be executed. When profile is executed it can potentially write to stdout. When the results of unsudo is piped elsewhere this output is unexpected and causes problem.

For a real life example this what raspberry pi profile includes /etc/profile.d/sshpwd.sh:

export TEXTDOMAIN=Linux-PAM

. gettext.sh

if [ -e /run/sshwarn ] ; then
    echo
        echo $(/usr/bin/gettext "SSH is enabled and the default password for the 'pi' user has not been changed.")
        echo $(/usr/bin/gettext "This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.")
        echo
fi

It is easy enough to disable this warning, but the point is, that when sudo -i is used you cannot really expect stdout to be just the stdout of the command run.

change /usr/local/go check

in my local machine /usr/local/go is a directory, not a symlink. so the script fails with
rm: cannot remove '/usr/local/go': Is a directory
you can handle it and move the dir to /tmp or ~ and continue the script.

1.15 ?

So... trying to install new go, for bettercap compatibility.

I have deleted Uninstaller removed purged et cetera go 1.15. I have installed go 1.20 with every means possible.

No matter what, go version returns 1.15 and somehow 1.15 is what's being installed?

Hopping in to say Thank You!!

Thank you for putting this out there! Was very easy and seamless! I guess I could have just downloaded the executable and put in /usr/local/bin but this was much more fun!

Checksum did not match?

I checked for the checksum, following the one in the docs and I got

$ update-golang.sh: FAILED
$ sha256sum: WARNING: 1 computed checksum did NOT match

What to do after this? Sorry for the noob question, kind of new in sum checking.

Some errors on Travis CI (Trusty)

$ curl -s https://raw.githubusercontent.com/udhos/update-golang/master/update-golang.sh | sudo bash -
...
bash: remove_old_link: not found symlink for old install
bash: untar: tar -x -f /usr/local/go1.10.3.linux-amd64.tar.gz
...
bash: testing: /usr/local/go/bin/go run /tmp/hello-tmp7iX7wIGO.go
# internal/race
flag provided but not defined: -std
...
# errors
flag provided but not defined: -std
...
go tool asm: exit status 2
flag provided but not defined: -V
usage: asm [options] file.s
...
go tool asm: exit status 2
flag provided but not defined: -V
usage: asm [options] file.s
...
bash: /usr/local/go/bin/go run /tmp/hello-tmp7iX7wIGO.go FAIL

See: build 401957176

But at the end it installs, so I'm not sure if that's the issue with the script or not.

Related:

Trouble Installing Go

sudo ./update-golang.sh
update-golang.sh: version 0.20
update-golang.sh: find_latest: found last release: 1.12.3
update-golang.sh: user: uid=0(root) gid=0(wheel) groups=0(wheel),1(daemon),2(kmem),3(sys),4(tty),5(operator),8(procview),9(procmod),12(everyone),20(staff),29(certusers),61(localaccounts),80(admin),701(com.apple.sharepoint.group.1),33(_appstore),98(_lpadmin),100(_lpoperator),204(_developer),250(_analyticsusers),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh)
update-golang.sh: RELEASE_LIST=https://golang.org/dl/
update-golang.sh: SOURCE=https://storage.googleapis.com/golang
update-golang.sh: DESTINATION=/usr/local
update-golang.sh: RELEASE=1.12.3
update-golang.sh: OS=darwin
update-golang.sh: ARCH_PROBE=uname -m
update-golang.sh: ARCH=amd64
update-golang.sh: PROFILED=/etc/profile.d/golang_path.sh
update-golang.sh: CACHE=/usr/local
update-golang.sh: GOPATH=
update-golang.sh: DEBUG=
update-golang.sh: will install golang go1.12.3.darwin-amd64 as: /usr/local/go
update-golang.sh: https://storage.googleapis.com/golang/go1.12.3.darwin-amd64.tar.gz is remote
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  121M  100  121M    0     0  18.8M      0  0:00:06  0:00:06 --:--:-- 20.8M
update-golang.sh: remove_old_link: not found symlink for old install
update-golang.sh: untar: tar -x -f /usr/local/go1.12.3.darwin-amd64.tar.gz
update-golang.sh: profile_path_add: issuing new /usr/local/go/bin to /etc/profile.d/golang_path.sh
./update-golang.sh: line 271: /etc/profile.d/golang_path.sh: No such file or directory
update-golang.sh: profile_path_add: issuing $HOME/go/bin to /etc/profile.d/golang_path.sh
./update-golang.sh: line 277: /etc/profile.d/golang_path.sh: No such file or directory
update-golang.sh: golang go1.12.3.darwin-amd64 installed at: /usr/local/go
update-golang.sh: testing: /usr/local/go/bin/go version
update-golang.sh: go version go1.12.3 darwin/amd64
update-golang.sh: /usr/local/go/bin/go version: SUCCESS
update-golang.sh: testing: /usr/local/go/bin/go run /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/hello-tmpXXXXXXXX.go.I1oHhd1w
package /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/hello-tmpXXXXXXXX.go.I1oHhd1w: import "/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/hello-tmpXXXXXXXX.go.I1oHhd1w": cannot import absolute path
update-golang.sh: /usr/local/go/bin/go run /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/hello-tmpXXXXXXXX.go.I1oHhd1w FAIL
update-golang.sh: running_as_root: yes
update-golang.sh: recursively forcing build cache [/Users/chen/Library/Caches/go-build] ownership to 501:20

I don't have go installed on this machine, tried running the script and it gives me a FAIL. Any ideas? Thanks

not work now

# sudo ./update-golang.sh
update-golang.sh: version 0.19
update-golang.sh: find_latest: found last release: 1.12
update-golang.sh: user: uid=0(root) gid=0(root) 所属グループ=0(root)
update-golang.sh: RELEASE_LIST=https://golang.org/dl/
update-golang.sh: SOURCE=https://storage.googleapis.com/golang
update-golang.sh: DESTINATION=/usr/local
update-golang.sh: RELEASE=1.12
update-golang.sh: OS=linux
update-golang.sh: ARCH_PROBE=uname -m
update-golang.sh: ARCH=amd64
update-golang.sh: PROFILED=/etc/profile.d/golang_path.sh
update-golang.sh: CACHE=/usr/local
update-golang.sh: GOPATH=
update-golang.sh: DEBUG=
update-golang.sh: will install golang go1.12.linux-amd64 as: /usr/local/go
update-golang.sh: https://storage.googleapis.com/golang/go1.12.linux-amd64.tar.gz is remote
--2018-12-22 14:35:33--  https://storage.googleapis.com/golang/go1.12.linux-amd64.tar.gz
storage.googleapis.com をDNSに問いあわせています... 172.217.24.144, 2404:6800:4004:807::2010
storage.googleapis.com|172.217.24.144|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 404 Not Found
2018-12-22 14:35:33 エラー 404: Not Found。

update-golang.sh: die: could not download using wget from: https://storage.googleapis.com/golang/go1.12.linux-amd64.tar.gz


# sudo ./update-golang.sh
update-golang.sh: version 0.19
update-golang.sh: find_latest: found last release: 1.12
update-golang.sh: user: uid=0(root) gid=0(root) 所属グループ=0(root)
update-golang.sh: RELEASE_LIST=https://golang.org/dl/
update-golang.sh: SOURCE=https://storage.googleapis.com/golang
update-golang.sh: DESTINATION=/usr/local
update-golang.sh: RELEASE=1.12
update-golang.sh: OS=linux
update-golang.sh: ARCH_PROBE=uname -m
update-golang.sh: ARCH=amd64
update-golang.sh: PROFILED=/etc/profile.d/golang_path.sh
update-golang.sh: CACHE=/usr/local
update-golang.sh: GOPATH=
update-golang.sh: DEBUG=
update-golang.sh: will install golang go1.12.linux-amd64 as: /usr/local/go
update-golang.sh: https://storage.googleapis.com/golang/go1.12.linux-amd64.tar.gz is remote
update-golang.sh: no need to download - file cached: /usr/local/go1.12.linux-amd64.tar.gz
update-golang.sh: remove_old_link: not found symlink for old install
update-golang.sh: previous install renamed to: /usr/local/go-20181222-143548
update-golang.sh: untar: tar -x -f /usr/local/go1.12.linux-amd64.tar.gz
tar: これは tar アーカイブではないようです

gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now
update-golang.sh: die: untar: failed: /usr/local/go1.12.linux-amd64.tar.gz
update-golang.sh: remember to delete previous install saved as: /usr/local/go-20181222-143548

No longer detecting latest version

I cloned the repo in a local directory.
Was on Go version 1.17.6. Wanted to update it to 1.17.7.
Script installed the default v1.16.4. Did not detect the latest version.
Manually edits "1.16.4" to "1.17.7" to run the script.

Auto-detect latest version seems to be broken now.

Example of two versions installed at once?

Sometimes I need to A/B test something across two Go versions, say latest and latest - 1, to compare for regressions.

How would you recommend running this to keep two versions installed?

Would be nice if I could have go1.19 in my PATH plus go as the latest version, for example.

And what would be the best way to wipe out the secondary installations?

I'm sure it can be done with the env vars config, but I think it would be helpful to have an explanation in the README.

Empty line at .profile file

profile_path_add() {
profile_path_remove
{ echo; echo "# DO NOT EDIT: installed by $path_mark"; echo ""; } >> "$abs_profiled"

That double echo makes script related entries at .profile file go down 1 line on every execution. Like

...
#
# DO NOT EDIT: installed by...

and at second run;

...
#

# DO NOT EDIT: installed by

Empty line between 2 "#" increases every script execution. After few month of cronjob, like 100 empty line between rest of the .profile file entries and script related entries.

GoLang update from 1.10 to latest

Hi Team,
What all the factors should we consider before updating go lang version to the latest.
Please help us with this.
Thank You.

Source profile upon creation

After executing sudo ./update-golang.sh (when performing a clean install), I expect to immediately be able to run go commands from anywhere. However, since the profile modifications aren't sourced after being created or updated, the user will have to either do it themselves manually or re-login to their session to access it globally.

Suggested changes:
Add source "$abs_profiled" after line #320

`fatal: not a git repository (or any of the parent directories): .git`

-fatal: not a git repository (or any of the parent directories): .git

Can you please post those error logs at https://github.com/udhos/update-golang/issues

and also please include the output for go env ?

source: https://gist.github.com/nikhita/432436d570b89cab172dcf2894465753#gistcomment-3870962

+:~/update-golang$ sudo ./update-golang.sh
[sudo] password for englianhu: 
update-golang.sh: version 0.24
update-golang.sh: parsing with jq from https://golang.org/dl/?mode=json
update-golang.sh: find_latest: found last release: 1.17
update-golang.sh: user: uid=0(root) gid=0(root) groups=0(root)
update-golang.sh: RELEASE_LIST=https://golang.org/dl/
update-golang.sh: SOURCE=https://storage.googleapis.com/golang
update-golang.sh: DESTINATION=/usr/local
update-golang.sh: RELEASE=1.17
update-golang.sh: OS=linux
update-golang.sh: ARCH_PROBE=uname -m
update-golang.sh: ARCH=amd64
update-golang.sh: PROFILED=/etc/profile.d/golang_path.sh
update-golang.sh: CACHE=/usr/local
update-golang.sh: GOPATH=
update-golang.sh: DEBUG=
update-golang.sh: 
update-golang.sh: will install golang go1.17.linux-amd64 as: /usr/local/go
update-golang.sh: https://storage.googleapis.com/golang/go1.17.linux-amd64.tar.gz is remote
update-golang.sh: no need to download - file cached: /usr/local/go1.17.linux-amd64.tar.gz
update-golang.sh: remove_old_link: found symlink for old install: /usr/local/go1.17.linux-amd64
update-golang.sh: untar: rm_dir /usr/local/go1.17.linux-amd64
update-golang.sh: untar: tar -x -f /usr/local/go1.17.linux-amd64.tar.gz
update-golang.sh: profile_path_remove: removing old settings from: /etc/profile.d/golang_path.sh
update-golang.sh: profile_path_add: issuing new /usr/local/go/bin to /etc/profile.d/golang_path.sh
update-golang.sh: profile_path_add: issuing $HOME/go/bin to /etc/profile.d/golang_path.sh
update-golang.sh: golang go1.17.linux-amd64 installed at: /usr/local/go
update-golang.sh: testing: /usr/local/go/bin/go version
update-golang.sh: unsudo: running_as_root:englianhu: /usr/local/go/bin/go version
-fatal: not a git repository (or any of the parent directories): .git
-can't load package: package .: no Go files in /home/englianhu
-can't load package: package .: no Go files in /home/englianhu
update-golang.sh: go version go1.17 linux/amd64
update-golang.sh: /usr/local/go/bin/go version: SUCCESS
update-golang.sh: unsudo: running_as_root:englianhu: mktemp -t hello-tmpXXXXXXXX
-fatal: not a git repository (or any of the parent directories): .git
-can't load package: package .: no Go files in /home/englianhu
-can't load package: package .: no Go files in /home/englianhu
update-golang.sh: unsudo: running_as_root:englianhu: tee /tmp/hello-tmp5siDP3Qg.go
-fatal: not a git repository (or any of the parent directories): .git
-can't load package: package .: no Go files in /home/englianhu
-can't load package: package .: no Go files in /home/englianhu
update-golang.sh: testing: /usr/local/go/bin/go run /tmp/hello-tmp5siDP3Qg.go
update-golang.sh: unsudo: running_as_root:englianhu: /usr/local/go/bin/go run /tmp/hello-tmp5siDP3Qg.go
-fatal: not a git repository (or any of the parent directories): .git
-can't load package: package .: no Go files in /home/englianhu
-can't load package: package .: no Go files in /home/englianhu
update-golang.sh: hello, world - go1.17
update-golang.sh: /usr/local/go/bin/go run /tmp/hello-tmp5siDP3Qg.go: SUCCESS
update-golang.sh: running_as_root: yes
-fatal: not a git repository (or any of the parent directories): .git
-can't load package: package .: no Go files in /home/englianhu
-can't load package: package .: no Go files in /home/englianhu
update-golang.sh: recursively forcing build cache [/home/englianhu/.cache/go-build] ownership to 1000:1000
update-golang.sh: cleanup: /tmp/profile-tmpW8occx3O
+:~/update-golang$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/englianhu/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/englianhu/golang"
GOPROXY=""
GORACE=""
GOROOT="/usr"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/gcc/x86_64-linux-gnu/9"
GCCGO="/usr/bin/x86_64-linux-gnu-gccgo-9"
CC="x86_64-linux-gnu-gcc-9"
CXX="x86_64-linux-gnu-g++-9"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build397497347=/tmp/go-build -gno-record-gcc-switches -funwind-tables"

Checksum verification failed

After doing:

git clone https://github.com/udhos/update-golang.git
cd update-golang/
wget -qO hash.txt https://raw.githubusercontent.com/udhos/update-golang/master/update-golang.sh.sha256
sha256sum -c hash.txt

Receiving:

update-golang.sh: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match

cat hash.txt
efbb43fef632cd9b880ad969ae54bcd107990ee98063bfbd38148e4c094d8c94  update-golang.sh
sha256sum update-golang.sh
927a7902a66d3d6ff9df62765af2e1da4790ef5f14cfa75ae3f2cb1bdb8e4f8b  update-golang.sh

Posix shell compatibility

hello,
you can switch from bash to sh and adjust your script if necessary. sh is a posix conform, because bash is not the standard shell for all go operating systems.

#!/usr/bin/sh

thanks

Fails in curl-only environment, possibly after switched to go.dev

Hello,
Today I realized that my CI starts to fails when it tries to un-tar the .tar.gz file. (e.g. go1.19.linux-amd64.tar.gz)
(which means I'm using your work pretty much every day. I appreciate it so much)

I found that curl -o https://go.dev/dl/go*.tar.gz (e.g. https://go.dev/dl/go1.19.linux-amd64.tar.gz) seems to download an HTML file that contains a tagged hyperlink text to the tar.gz in it, in stead of the tar.gz itself.
On the other hand, executing wget -O seems to download decent tar.gz itself for some reason.

Although I successfully worked around that problem by just installing and using wget instead of curl so that it never bothers me anymore, I'm just here to let you know it just in case you haven't noticed.

Thanks

Cannot install Go for the first time in Mac

Hi, I am on a Mac and unfortunately the installation does not seem to complete cleanly given that I have no previous Go installation.

Here's the output:

update-golang.sh: version 0.12
update-golang.sh: user: uid=0(root) gid=0(wheel) groups=0(wheel),1(daemon),2(kmem),3(sys),4(tty),5(operator),8(procview),9(procmod),12(everyone),20(staff),29(certusers),61(localaccounts),80(admin),701(com.apple.sharepoint.group.1),33(_appstore),98(_lpadmin),100(_lpoperator),204(_developer),250(_analyticsusers),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh),702(com.apple.sharepoint.group.2)
update-golang.sh: SOURCE=https://storage.googleapis.com/golang
update-golang.sh: DESTINATION=/usr/local
update-golang.sh: RELEASE=1.9.2
update-golang.sh: OS=darwin
update-golang.sh: ARCH_PROBE=uname -m
update-golang.sh: ARCH=amd64
update-golang.sh: PROFILED=/etc/profile.d/golang_path.sh
update-golang.sh: CACHE=/usr/local
update-golang.sh: GOPATH=
update-golang.sh: DEBUG=
update-golang.sh: will install golang go1.9.2.darwin-amd64 as: /usr/local/go
update-golang.sh: https://storage.googleapis.com/golang/go1.9.2.darwin-amd64.tar.gz is remote
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 97.6M  100 97.6M    0     0  8588k      0  0:00:11  0:00:11 --:--:-- 8644k
update-golang.sh: remove_old_link: not found symlink for old install
update-golang.sh: untar: tar -x -f /usr/local/go1.9.2.darwin-amd64.tar.gz
update-golang.sh: path: issuing new /usr/local/go/bin to /etc/profile.d/golang_path.sh
./update-golang.sh: line 222: /etc/profile.d/golang_path.sh: No such file or directory
update-golang.sh: path: issuing /Users/renato.athaydes/go/bin to /etc/profile.d/golang_path.sh
./update-golang.sh: line 228: /etc/profile.d/golang_path.sh: No such file or directory
update-golang.sh: golang go1.9.2.darwin-amd64 installed at: /usr/local/go
update-golang.sh: testing: /usr/local/go/bin/go version
update-golang.sh: go version go1.9.2 darwin/amd64
update-golang.sh: /usr/local/go/bin/go version: SUCCESS
update-golang.sh: testing: /usr/local/go/bin/go run /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/hello-tmpXXXXXXXX.go.Hg0nEzFb
go run: no go files listed
update-golang.sh: /usr/local/go/bin/go run /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/hello-tmpXXXXXXXX.go.Hg0nEzFb FAIL

Running it again results in a similar error... go does get installed but not completely, i.e. it's not added to PATH so running just go doesn't work, but /usr/local/go/bin/go does.

What do you think? Anything I should do to finalize the installation properly?

go build runtime/cgo: open /usr/local/go/pkg/linux_amd64/runtime/cgo.a: permission denied

I don't know how this happened, I was using update-golang.sh a while and was always good. Can't remember which golang version I was when this error happened, so I was thinking, give the update a go. The following commands are after installing 1.11.1 already.

Installing:

myuser@nb-myuser:~/Projects/go/src/github.com/udhos/update-golang$ sudo ./update-golang.sh 
[sudo] password for myuser: 
update-golang.sh: version 0.17
update-golang.sh: find_latest: found last release: 1.11.1
update-golang.sh: user: uid=0(root) gid=0(root) groups=0(root)
update-golang.sh: RELEASE_LIST=https://golang.org/doc/devel/release.html
update-golang.sh: SOURCE=https://storage.googleapis.com/golang
update-golang.sh: DESTINATION=/usr/local
update-golang.sh: RELEASE=1.11.1
update-golang.sh: OS=linux
update-golang.sh: ARCH_PROBE=uname -m
update-golang.sh: ARCH=amd64
update-golang.sh: PROFILED=/etc/profile.d/golang_path.sh
update-golang.sh: CACHE=/usr/local
update-golang.sh: GOPATH=
update-golang.sh: DEBUG=
update-golang.sh: will install golang go1.11.1.linux-amd64 as: /usr/local/go
update-golang.sh: https://storage.googleapis.com/golang/go1.11.1.linux-amd64.tar.gz is remote
update-golang.sh: no need to download - file cached: /usr/local/go1.11.1.linux-amd64.tar.gz
update-golang.sh: remove_old_link: found symlink for old install: /usr/local/go1.11.1.linux-amd64
update-golang.sh: untar: rm_dir /usr/local/go1.11.1.linux-amd64
update-golang.sh: untar: tar -x -f /usr/local/go1.11.1.linux-amd64.tar.gz
update-golang.sh: path: removing old settings from: /etc/profile.d/golang_path.sh
update-golang.sh: path: issuing new /usr/local/go/bin to /etc/profile.d/golang_path.sh
update-golang.sh: path: issuing /home/myuser/go/bin to /etc/profile.d/golang_path.sh
update-golang.sh: golang go1.11.1.linux-amd64 installed at: /usr/local/go
update-golang.sh: testing: /usr/local/go/bin/go version
update-golang.sh: go version go1.11.1 linux/amd64
update-golang.sh: /usr/local/go/bin/go version: SUCCESS
update-golang.sh: testing: /usr/local/go/bin/go run /tmp/hello-tmpEMefkQLD.go
update-golang.sh: hello, world
update-golang.sh: /usr/local/go/bin/go run /tmp/hello-tmpEMefkQLD.go: SUCCESS
update-golang.sh: running_as_root: yes
update-golang.sh: recursively forcing build cache [/home/myuser/.cache/go-build] ownership to 1000:1000
update-golang.sh: cleanup: /tmp/tmp.vm4MxFOfkz

Build a project:

myuser@nb-myuser:~/Projects/go/src/github.com/udhos/update-golang$ cd ~/Projects/go/src/example.io/somegroup/somerepo/
myuser@nb-myuser:~/Projects/go/src/example.io/somegroup/somerepo$ go build -i -o bin/srvdef ./cmd/srvdef
go build runtime/cgo: open /usr/local/go/pkg/linux_amd64/runtime/cgo.a: permission denied
make: *** [build] Error 1

go info:

myuser@nb-myuser:~/Projects/go/src/example.io/somegroup/somerepo$ cd
myuser@nb-myuser:~$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/myuser/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/myuser/Projects/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-I/home/myuser/Projects/go/deps/sqlite/ -I/home/myuser/Projects/go/deps/dqlite/include/"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-L/home/myuser/Projects/go/deps/sqlite/.libs/ -L/home/myuser/Projects/go/deps/dqlite/.libs/"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build757453316=/tmp/go-build -gno-record-gcc-switches"
myuser@nb-myuser:~$ go version
go version go1.11.1 linux/amd64

Persmissions look good to me:

myuser@nb-myuser:~$ ls -lah /usr/local/go
lrwxrwxrwx 1 root root 31 Okt 29 16:41 /usr/local/go -> /usr/local/go1.11.1.linux-amd64
myuser@nb-myuser:~$ ls -lah /usr/local/go/pkg
...
drwxr-xr-x 29 root root 4.0K Okt  1 23:15 linux_amd64
...
myuser@nb-myuser:~$ ls -lah /usr/local/go/pkg/linux_amd64
...
drwxr-xr-x  4 root root 4.0K Okt  1 23:04 runtime
...
myuser@nb-myuser:~$ ls -lah /usr/local/go/pkg/linux_amd64/runtime
...
-rw-r--r--  1 root root  95K Okt  1 23:04 cgo.a
...

After Updating to 1.20 static analysis gave "fatal error: 'stdlib.h' file not found"

When fatal error: 'stdlib.h' file not found appears, there is a problem with cgo. Core gnu compilers are included here. The error is simple to fix with: sudo apt-get install build-essential

Now, that should have already been installed (since I had no previous issue) and I can't see how the script would have affected it. For this reason, I did not make a commit with this on line 542 of update-golang.sh, but perhaps others encounter this issue and something similar would be necessary.

profile_path_remove: could not create temporary file

$ sudo ./update-golang.sh remove

update-golang.sh: version 0.20
update-golang.sh: find_latest: found last release: 1.12.4
update-golang.sh: remove: found symlink for old install: /usr/local/go1.12.4.darwin-amd64
update-golang.sh: remove: removing symlink: /usr/local/go
update-golang.sh: remove: removing dir: /usr/local/go1.12.4.darwin-amd64
update-golang.sh: profile_path_remove: removing old settings from: /etc/profile
mktemp: option requires an argument -- t
usage: mktemp [-d] [-q] [-t prefix] [-u] template ...
       mktemp [-d] [-q] [-u] -t prefix 
update-golang.sh: profile_path_remove: could not create temporary file: 

Happened on macOS: 10.14.4

raspberrypi 3 golang download issue

doesn't work with a pi3

update-golang.sh: version 0.6
update-golang.sh: user: uid=0(root) gid=0(root) groups=0(root)
update-golang.sh: SOURCE=https://storage.googleapis.com/golang
update-golang.sh: DESTINATION=/usr/local
update-golang.sh: RELEASE=1.8.1
update-golang.sh: OS=linux
update-golang.sh: ARCH=armv7l
update-golang.sh: PROFILED=/etc/profile.d/golang_path.sh
update-golang.sh: CACHE=/usr/local
update-golang.sh: GOPATH=
update-golang.sh: DEBUG=
update-golang.sh: will install golang go1.8.1.linux-armv7l as: /usr/local/go
update-golang.sh: https://storage.googleapis.com/golang/go1.8.1.linux-armv7l.tar.gz is remote
--2017-05-08 10:14:17--  https://storage.googleapis.com/golang/go1.8.1.linux-armv7l.tar.gz
Resolving storage.googleapis.com (storage.googleapis.com)... 2a00:1450:4001:81b::2010, 172.217.22.80
Connecting to storage.googleapis.com (storage.googleapis.com)|2a00:1450:4001:81b::2010|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-05-08 10:14:18 ERROR 404: Not Found.

update-golang.sh: could not download using wget from: https://storage.googleapis.com/golang/go1.8.1.linux-armv7l.tar.gz

archive is not removed after installation

I have noticed that downloaded archive is not deleted after successful golang upgrade.
Archive is stored as /usr/local/go1.15.5.linux-amd64.tar.gz, had to manually remove it.
I imagine that archives would pile up clogging the directory

Go not usable directly after update-golang.sh

Hi,

I've tried to embed your Golang script in one of my own install scripts that runs on a rpi3. update-golang.sh finishes successful, but I'm not able to use go commands such as go env, go version or go get github.com/dev/tool .. After a reboot it seems to work and I can install the tools. Any ideas/solution for this issue?

GitHub Sponsors

I have gone through the agony of quitting vim.

I have burned down a couple of houses running Android Studio.

I have seen code so bad it made me want to quit programming.

But nothing, nothing in my career compares to the struggles I’ve endured trying to manually update golang.

This script brought tears of joy for me and presumably thousands of others who have ⭐ this repo. Have you considered signing up for GitHub Sponsors so we have a way to thank you?!

Problem at installing go

Ubuntu 22.04

update-golang.sh: find_latest: FAILED
update-golang.sh: user: uid=0(root) gid=0(root) groups=0(root)
update-golang.sh: 
update-golang.sh: RELEASE_LIST=https://go.dev/dl/
update-golang.sh: SOURCE=https://storage.googleapis.com/golang
update-golang.sh: DESTINATION=/usr/local
update-golang.sh: RELEASE=1.21.4
update-golang.sh: OS=linux
update-golang.sh: ARCH_PROBE=uname -m
update-golang.sh: ARCH=amd64
update-golang.sh: PROFILED=/etc/profile.d/golang_path.sh
update-golang.sh: CACHE=/usr/local
update-golang.sh: GOPATH=
update-golang.sh: DEBUG=
update-golang.sh: FORCE_IPV4=           ;# set FORCE_IPV4=-4 to force IPv4
update-golang.sh: CONNECT_TIMEOUT=5
update-golang.sh: SKIP_WGET=             ;# set SKIP_WGET=1 to skip wget
update-golang.sh: 
update-golang.sh: will install golang go1.21.4.linux-amd64 as: /usr/local/go
update-golang.sh: https://storage.googleapis.com/golang/go1.21.4.linux-amd64.tar.gz is remote
update-golang.sh: no need to download - file cached: /usr/local/go1.21.4.linux-amd64.tar.gz
update-golang.sh: remove_old_link: not found symlink for old install
update-golang.sh: untar: tar -x -f /usr/local/go1.21.4.linux-amd64.tar.gz
tar: This does not look like a tar archive

gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now
update-golang.sh: die: untar: failed: /usr/local/go1.21.4.linux-amd64.tar.gz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.