How do I update golang from command prompt on Windows?

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

How do I update golang from command prompt on Windows?

问题

你好!你想要将golang从1.7版本升级到1.8版本,并且想知道是否可以在Windows 8.1的命令提示符中使用命令来进行更新。卸载并重新安装是一种选择,但你是否可以使用命令来进行更新呢?

英文:

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?

答案1

得分: 24

Go语言也可以使用Chocolatey软件包管理器进行更新。在提升的shell中运行以最小化安装问题的风险。

安装命令:

choco install golang -y

更新命令:

choco upgrade golang -y
英文:

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

答案2

得分: 7

我认为GVM可能是一个不错的选择。GVM是一个用于管理计算机中Go版本的接口。它允许您通过命令提示符更改Go版本,甚至可以安装/卸载不同的golang版本。

您可以通过输入以下命令来安装新版本:

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

或者获取计算机中已安装的golang版本列表:

gvm list

更多信息可以在他们的网站上找到:https://github.com/moovweb/gvm

英文:

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

答案3

得分: 3

在Windows上安装Go语言的“正常”方式是使用MSI安装程序,可以在此处找到:https://golang.org/dl/。

如果你真的想通过命令行来安装,你需要知道Go语言的版本(当前版本是1.13.4)。我可以想到几种方法,包括从Go语言网站上获取信息或者使用与最新版本匹配的Docker镜像标签。

如果你是出于管理目的进行安装,版本号也可以作为系统中的一个输入变量。

一旦你知道需要的版本号,你可以从https://dl.google.com/go/go<version>.windows-amd64.msi下载相应的文件。你可以使用类似于Windows的wget或者PowerShell的功能来下载:

Invoke-WebRequest -OutFile go1.13.4.windows-amd64.msi https://dl.google.com/go/go1.13.4.windows-amd64.msi

然后你可以使用MSI安装程序的静默模式来安装:

msiexec.exe /package go1.13.4.windows-amd64.msi /quiet
英文:

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 need 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&lt;version&gt;.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

答案4

得分: 1

如果按照David建议的使用Chocolatey模式进行升级,有可能您系统上定义的GOPATH与现有的GOPATH不匹配(如果您通过手动安装设置了自定义路径)。
Chocolatey会将Go二进制文件安装在%USERPROFILE%/go/bin下,即C:\Program Files\Go\bin。
因此,请确保路径正确,并相应地更新您的环境变量。

如果路径发生变化,安装消息可能如下所示。

"环境变量(如PATH)已更改。关闭/重新打开您的shell以查看更改(或在powershell/cmd.exe中只需键入'refreshenv')。
golang的升级成功。
软件已安装为'msi',安装位置可能是默认位置。
"

英文:

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

答案5

得分: -12

一个简单的方法是使用update-golang脚本:

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

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

huangapple
  • 本文由 发表于 2017年4月23日 17:50:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/43569617.html
匿名

发表评论

匿名网友

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

确定