简体   繁体   中英

How do I update golang from command prompt on Windows?

I have 1.7 version of golang and I want to update golang to 1.8 from command prompt. Uninstalling and Installing it again is always an option, but can I update it using commands on Windows 8.1?

I think that GVM could be a good option for that. GVM is an interface to manage Go versions in your computer. It allows you to change the Go version and even installing/uninstalling different golang versions by command prompt.

You can install a new version by typing:

gvm install go1.4 -B
gvm use go1.4
export GOROOT_BOOTSTRAP=$GOROOT
gvm install go1.5

Or even get a list of golang versions installed in your computer:

gvm list

More information can be found on their website: https://github.com/moovweb/gvm

Go can also be updated using the Chocolatey package manager. Run from an elevated shell to minimize the risk of installation issues.

Install using:

choco install golang -y

Update using:

choco upgrade golang -y

The "normal" way for Windows is to use the MSI package that can be found here : https://golang.org/dl/ .

Now if you really want to do it from the command line, you will nee d to know the version (current is 1.13.4). There are several ways I can think of, including scraping the golang website or leveraging the Docker tags matching image with latest .
If you're doing this for administrative reasons, the version can also easily just be an input variable in your system.

Once you know the version you need to download the file at https://dl.google.com/go/go<version>.windows-amd64.msi .
You can use something like wget for Windows or just Powershell capabilities :
Invoke-WebRequest -OutFile go1.13.4.windows-amd64.msi https://dl.google.com/go/go1.13.4.windows-amd64.msi

Then you can just use the MSI in quiet mode :
msiexec.exe /package go1.13.4.windows-amd64.msi /quiet

If using Chocolatey mode of upgrade as David suggested, there is a possibility that the GOPATH defined on your system may not match with the existing one (if you had set a custom path via manual install). Chocolatey, will install the Go binaries under %USERPROFILE%/go/bin --> C:\\Program Files\\Go\\bin So please ensure the path and update your environment variables accordingly.

Installation message may look something like below, if the path changes.

" Environment Vars (like PATH) have changed. Close/reopen your shell to see the changes (or in powershell/cmd.exe just type refreshenv ). The upgrade of golang was successful. Software installed as 'msi', install location is likely default. "

A simple way is to use the update-golang script:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM