更新Go语言使用`go install`命令。

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

Update go using go install

问题

如何使用go install命令更新现有版本的go

我已经完成了以下步骤:

$ go install golang.org/dl/go1.19.4@latest
go: 正在下载 golang.org/dl v0.0.0-20221207214018-bd7282711064

$ go1.19.4 download
已下载   0.0% (    16384 / 148931745 字节) ...
已下载   9.2% ( 13647776 / 148931745 字节) ...
已下载  36.2% ( 53870192 / 148931745 字节) ...
已下载  61.8% ( 92028240 / 148931745 字节) ...
已下载  87.4% (130137120 / 148931745 字节) ...
已下载 100.0% (148931745 / 148931745 字节)
正在解压缩 /home/gameveloster/sdk/go1.19.4/go1.19.4.linux-amd64.tar.gz ...
成功。现在可以运行 'go1.19.4'

$ which go1.19.4
/home/gameveloster/go/bin/go1.19.4

$ which go
/home/gameveloster/.go/bin/go

最后一步是将新下载的go二进制文件~/go/bin/go1.19.4复制到现有的~/.go/bin/go中吗?

然后,是否有特殊的方法来清理~/go/bin/go1.19.4,还是简单地删除该二进制文件就足够了?

英文:

How can the existing version of go be updated using the go install command?

I've done the following

$ go install golang.org/dl/go1.19.4@latest
go: downloading golang.org/dl v0.0.0-20221207214018-bd7282711064

$ go1.19.4 download
Downloaded   0.0% (    16384 / 148931745 bytes) ...
Downloaded   9.2% ( 13647776 / 148931745 bytes) ...
Downloaded  36.2% ( 53870192 / 148931745 bytes) ...
Downloaded  61.8% ( 92028240 / 148931745 bytes) ...
Downloaded  87.4% (130137120 / 148931745 bytes) ...
Downloaded 100.0% (148931745 / 148931745 bytes)
Unpacking /home/gameveloster/sdk/go1.19.4/go1.19.4.linux-amd64.tar.gz ...
Success. You may now run 'go1.19.4'

$ which go1.19.4
/home/gameveloster/go/bin/go1.19.4

$ which go
/home/gameveloster/.go/bin/go

Is the final step to copy the newly downloaded go binary ~/go/bin/go1.19.4 to replace the existing ~/.go/bin/go?

Is there a special way to then clean up ~/go/bin/go1.19.4, or is simply deleting this binary sufficient?

答案1

得分: 2

简短回答是不可以直接更新现有的Go版本
首先,你需要卸载当前安装的版本,然后再安装新版本。
以下是一个简单的解决方案:

要找到安装地址,请运行以下命令:

where go

要卸载,请删除上述命令输出的地址:

sudo rm -rf [上述命令的输出]

要检查是否已经卸载了Go,请运行以下命令;如果系统提示“找不到命令go”,则表示已经卸载:

go --version

现在安装新版本的Go:

wget https://go.dev/dl/go1.19.4.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.19.4.linux-amd64.tar.gz

确保你的PATH中包含 /usr/local/go/bin:

export PATH=$PATH:/usr/local/go/bin

之后,你需要重新启动终端才能使更改生效。
要检查是否成功安装了Go,请运行以下命令。

go --version

祝你使用愉快!

英文:

The short answer is No you can't update the existing version of go.
First, you have to uninstall the currently installed version and then install a newer version.
Here is an easy solution,

To find the installation address run

where go

To uninstall, delete the given address of above,

sudo rm -rf [output of above command]

To check if you already remove go, run the below command; the system will prompt "command go not found"

go --version

Now install a newer version of go

wget https://go.dev/dl/go1.19.4.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.19.4.linux-amd64.tar.gz

Make sure that your PATH contains /usr/local/go/bin

export PATH=$PATH:/usr/local/go/bin

After that, you will need to restart your terminal for the change to take effect.
To check if you have installed Go successfully, run the below command.

go --version

Enjoy!

答案2

得分: -1

如何使用"go install"命令更新现有版本的Go?

不可以。这不是管理Go安装的正确方式。能够使用"go install"命令安装特定版本的Go是一个不错的快捷方式,但这不是管理机器上的"Go"安装的预期方式。

英文:

> How can the existing version of go be updated using the go install command?

Not. That's simply not the way to manage the installation of Go. Being able to "go install" a certain version is a nice shortcut to get a certain version of Go up and running but it's not the intended way to manage "the" Go installation on your machine.

huangapple
  • 本文由 发表于 2022年12月31日 00:11:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/74963578.html
匿名

发表评论

匿名网友

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

确定