如何卸载Go?

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

How to uninstall Go?

问题

我在这里尝试了这个答案https://stackoverflow.com/questions/35643576/removed-golang-but-go-command-still-works,但是没有成功(我仍然可以运行go)。

目前,当我运行which go时,我看到以下输出:

/usr/local/go/bin/go

我想我安装了两个go版本,因为我的GOPATH指向了另一个名为gocode的文件夹。我现在已经删除了那个文件夹和usr/local/go/bin/go文件夹。

我也删除了我的GOPATH。然而,我仍然可以运行go

如何卸载go?

英文:

I tried the answer here https://stackoverflow.com/questions/35643576/removed-golang-but-go-command-still-works, but it didn't work (I can still run go)

Currently, when I run which go I see this output

/usr/local/go/bin/go

I think I had two installations of go as my GOPATH was pointing to another folder named gocode. I've now removed that folder, and the usr/local/go/bin/go folder.

I've also removed my GOPATH. However, I can still run go.

How do I uninstall go?

答案1

得分: 219

2019年8月更新

发现官方的卸载文档按预期工作(在Mac OSX上)。

$ which go
/usr/local/go/bin/go

总结一下,要卸载:

$ sudo rm -rf /usr/local/go
$ sudo rm /etc/paths.d/go

然后,使用Homebrew进行全新安装,使用brew install go。现在,我有:

$ which go
/usr/local/bin/go
英文:

Update August 2019

Found the official uninstall docs worked as expected (on Mac OSX).

$ which go
/usr/local/go/bin/go

In summary, to uninstall:

$ sudo rm -rf /usr/local/go
$ sudo rm /etc/paths.d/go

Then, did a fresh install with homebrew using brew install go. Now, i have:

 $ which go
/usr/local/bin/go

答案2

得分: 92

你可以尝试执行以下命令:

rm -rvf /usr/local/go/

然后在你的 ~/.bashrc 文件中删除任何关于 go 的提及;然后至少需要注销并重新登录。

但是,在执行此操作时要小心。如果出现问题,可能会严重破坏你的系统。

PS. 我假设你使用的是 Linux 或 POSIX 系统。

英文:

You might try

rm -rvf /usr/local/go/

then remove any mention of go in e.g. your ~/.bashrc; then you need at least to logout and login.

However, be careful when doing that. You might break your system badly if something is wrong.

<sup>PS. I am assuming a Linux or POSIX system.</sup>

答案3

得分: 78

我正在使用Ubuntu。我花了整个早上来解决这个问题,尝试了各种不同的解决方案,但当我输入"go version"时,问题仍然存在,真的很烦人...
最后,这个方法对我起作用了,希望对你也有帮助!

sudo apt-get remove golang-go
sudo apt-get remove --auto-remove golang-go
英文:

I'm using Ubuntu. I spent a whole morning fixing this, tried all different solutions, when I type go version, it's still there, really annoying...
Finally this worked for me, hope this will help!

sudo apt-get remove golang-go
sudo apt-get remove --auto-remove golang-go

答案4

得分: 18

在Mac-OS系统上

  1. 如果您使用了安装程序,可以使用相同的安装程序卸载golang。
  2. 如果您是从源代码安装的,请执行以下操作:
    rm -rf /usr/local/go
    rm -rf $(echo $GOPATH)
    

然后,从~/.bash_profile中删除与go相关的所有条目,例如GOROOT、GOPATH,并运行

source ~/.bash_profile

在Linux系统上

rm -rf /usr/local/go
rm -rf $(echo $GOPATH)

然后,从~/.bashrc中删除与go相关的所有条目,例如GOROOT、GOPATH,并运行

source ~/.bashrc
英文:

On a Mac-OS system

  1. If you have used an installer, you can uninstall golang by using the same installer.
  2. If you have installed from source
    rm -rf /usr/local/go
    rm -rf $(echo $GOPATH)
    

Then, remove all entries related to go i.e. GOROOT, GOPATH from ~/.bash_profile and run

source ~/.bash_profile

On a Linux system

rm -rf /usr/local/go
rm -rf $(echo $GOPATH)

Then, remove all entries related to go i.e. GOROOT, GOPATH from ~/.bashrc and run

source ~/.bashrc

答案5

得分: 13

更新(2022年9月)

官方页面已更改卸载帮助的路径以及帮助文本。以下是现在的说明:

卸载 Go

您可以按照本主题中描述的步骤从系统中删除 Go。

Linux / macOS / FreeBSD

  1. 删除 go 目录。
    通常位于 /usr/local/go。

  2. 从 PATH 环境变量中删除 Go 的 bin 目录。
    在 Linux 和 FreeBSD 下,编辑 /etc/profile 或 $HOME/.profile。
    如果您使用 macOS 包安装了 Go,请删除 /etc/paths.d/go 文件。

Windows

最简单的方法是通过 Windows 控制面板中的“添加/删除程序”来删除 Go:

  1. 在控制面板中,双击“添加/删除程序”。
  2. 在“添加/删除程序”中,选择“Go 编程语言”,点击“卸载”,然后按照提示进行操作。

要使用命令行删除 Go 工具,您也可以使用以下命令:

  • 通过运行以下命令使用命令行卸载:
    msiexec /x go{{version}}.windows-{{cpu-arch}}.msi /q
    注意: 使用此卸载过程将自动删除原始安装创建的 Windows 环境变量。

原始回答

根据官方安装页面

要从系统中删除现有的 Go 安装,请删除 go 目录。在 Linux、macOS 和 FreeBSD 下,通常是 /usr/local/go,在 Windows 下是 c:\Go

您还应该从 PATH 环境变量中删除 Go 的 bin 目录。在 Linux 和 FreeBSD 下,您应该编辑 /etc/profile$HOME/.profile。如果您使用 macOS 包 安装了 Go,则应删除 /etc/paths.d/go 文件。Windows 用户应阅读有关 在 Windows 下设置环境变量 的部分。

英文:

Update (Sep, 2022)

The official page has changed path for the uninstallation help along with the help text. Here is what it says now.

> ### Uninstalling Go
> You can remove Go from your system using the steps
> described in this topic.
>
> #### Linux / macOS / FreeBSD
> 1. Delete the go directory.
> This is usually
> /usr/local/go.
>
> 2. Remove the Go bin directory from your PATH environment variable.
> Under Linux and FreeBSD, edit /etc/profile or $HOME/.profile. If you
> installed Go with the macOS package, remove the /etc/paths.d/go file.
>
> #### Windows
> The simplest way to remove Go is via Add/Remove Programs in
> the Windows control panel:
>
> 1. In Control Panel, double-click Add/Remove Programs.
> 2. In Add/Remove
> Programs, select Go Programming Language, click Uninstall, then follow
> the prompts.
>
> For removing Go with tools, you can also use the command
> line:
>
> * Uninstall using the command line by running the following command:
> msiexec /x go{{version}}.windows-{{cpu-arch}}.msi /q
> Note: Using this
> uninstall process for Windows will automatically remove Windows
> environment variables created by the original installation.

Original Answer

From the official install page -

> To remove an existing Go installation from your system delete the go
> directory. This is usually /usr/local/go under Linux, macOS, and
> FreeBSD or c:\Go under Windows.
>
> You should also remove the Go bin directory from your PATH environment
> variable. Under Linux and FreeBSD you should edit /etc/profile or
> $HOME/.profile. If you installed Go with the macOS package then you
> should remove the /etc/paths.d/go file. Windows users should read the
> section about setting environment variables under Windows.

答案6

得分: 12

对于Windows 10:

  1. 打开“设置”应用中的“应用”选项。
  2. 在列表中查找“Go编程语言 *”,并卸载它。
  3. 如果您不打算安装其他版本的Go语言,请从您的“PATH”环境变量中移除“C:\Go\bin”。
英文:

For Windows 10:

  1. Go to Apps in the Settings App.
  2. Look for Go Programming Language * in the list and uninstall it.
  3. Remove C:\Go\bin from your PATH environment variable (only if you don't plan on installing another version of golang)

答案7

得分: 6

使用以下命令在Ubuntu上卸载Golang。

这将仅删除golang-go软件包本身。

sudo apt-get remove golang-go

卸载golang-go及其依赖项:

sudo apt-get remove --auto-remove golang-go
英文:

Use this command to uninstall Golang for Ubuntu.

This will remove just the golang-go package itself.

sudo apt-get remove golang-go

Uninstall golang-go and its dependencies:

sudo apt-get remove --auto-remove golang-go

答案8

得分: 4

在阅读其他答案中提到的如此基础的建议后,我只需要在这里回答。

对于 MacOS,默认的路径如下:

  1. /user/bracicot/go(工作目录)
  2. /usr/local/go(安装目录)

卸载时,请删除这两个目录。
如果你是手动安装的,显然这些目录可能在其他位置。

我遇到的一个脚本安装到了 /usr/local/.go/,这是一个隐藏文件夹,因为权限问题... 这可能会让你困扰。

在终端中检查:

echo $GOPATH
echo $GOROOT
#以及
go version

对我来说,即使删除了所有的 go 文件夹,我仍然得到了一个 go 版本。

通过查看我的系统路径 echo $PATH

/Users/bracicot/google-cloud-sdk/bin:/usr/local/bin:

发现了一些需要检查是否仍存在 go 文件的地方,比如 /usr/local/bin

另一个用户提到:/etc/paths.d/go

你可能还想删除 GOPATHGOROOT 环境变量。
检查 .zshsrc 和/或 .bash_profile。
或者你可以使用 unset GOPATHunset GOROOT

英文:

I just have to answer here after reading such super-basic advice in the other answers.

For MacOS the default paths are:

  1. /user/bracicot/go (working dir)
  2. /usr/local/go (install dir)

When uninstalling remove both directories.
If you've installed manually obviously these directories may be in other places.

One script I came across installed to /usr/local/.go/ a hidden folder because of permissioning... this could trip you up.

In terminal check:

echo $GOPATH
echo $GOROOT
#and
go version

For me after deleting all go folders I was still getting a go version.

Digging through my system path echo $PATH

/Users/bracicot/google-cloud-sdk/bin:/usr/local/bin:

revealed some places to check for still-existing go files such as /usr/local/bin

> Another user mentioned: /etc/paths.d/go

You may also want to remove GOPATH and GOROOT environment variables.
Check .zshsrc and or .bash_profile.
Or you can unset GOPATH and unset GOROOT

答案9

得分: 2

在MacOS上卸载go,请按照以下步骤操作:

  1. 打开终端,输入命令 which go,它会返回一个路径,类似于 /usr/local/go/bin/go

  2. 进入go的根目录,即 /usr/local/go/,在终端上输入命令 rm -rf /usr/local/go/。根据你的系统设置,可能会出现权限被拒绝的情况,所以命令前面需要加上sudo,像这样:

    sudo rm -rf /usr/local/go/

  3. 系统会要求输入密码,请输入密码即可。

英文:

To uninstall go on MacOS, do this:
On the terminal type which go it will; return a path like this /usr/local/go/bin/go
Go to the root folder of go which is /usr/local/go/ and type on the terminal rm -rf /usr/local/go/ . you may get permission denied depending on your system setup, so the command should be prefixed with sudo like this

sudo rm -rf /usr/local/go/

It will request for your password, just enter it.

答案10

得分: 1

以下是翻译好的内容:

sudo apt-get remove golang-go
sudo apt-get remove --auto-remove golang-go

这适用于Ubuntu 18.18版本。
英文:
sudo apt-get remove golang-go
sudo apt-get remove --auto-remove golang-go

This is perfect for Ubuntu 18.18

答案11

得分: 1

在Mac-OS Catalina上:

  1. 需要在rm -rf /usr/local/go之前添加sudo,即sudo rm -rf /usr/local/go,否则会遇到权限拒绝的问题。

  2. 使用sudo vim ~/.profile或sudo ~/.bash_profile,删除export PATH=$PATH:$GOPATH/BIN或与go语言相关的任何内容。

  3. 如果你使用的是Zsh shell,则需要在~/.zshrc文件中删除上述行。

希望对你有帮助 如何卸载Go?

英文:

On a Mac-OS Catalina

  1. need to add sudo before rm -rf /usr/local/go sudo rm -rf /usr/local/go
    otherwise, we will run into permission denial.

  2. sudo vim ~/.profile or sudo ~/.bash_profile remove export PATH=$PATH:$GOPATH/BIN or anything related to
    go lang

  3. If you use Zsh shell, then you need to remove the above line to ~/.zshrc file.

Hope it helps you 如何卸载Go?

答案12

得分: 0

在 MacOS 中,你可以使用 brew 来完成这个操作:

brew uninstall go
brew install go
brew upgrade go
英文:

In MacOS, you can just do it with brew:

brew uninstall go
brew install go
brew upgrade go

答案13

得分: -1

在Linux上,我们可以这样完全删除Go:

rm -rf "/usr/local/.go/"
rm -rf "/usr/local/go/"

这两个命令会删除Go及其隐藏的.go文件。现在我们还需要更新shell配置文件中的条目。

打开你的基本文件。通常我这样打开:sudo gedit ~/.bashrc,然后删除所有关于Go的提及。

你也可以在Ubuntu中使用sed命令来完成:

sed -i '/# GoLang/d' .bashrc
sed -i '/export GOROOT/d' .bashrc
sed -i '/:$GOROOT/d' .bashrc
sed -i '/export GOPATH/d' .bashrc
sed -i '/:$GOPATH/d' .bashrc

这将从所有地方删除Golang。在运行这些命令之后,还要运行以下命令:

source ~/.bash_profile

在Linux 18.04上测试通过。就是这样。

英文:

On linux we can do like this to remove go completely:

rm -rf &quot;/usr/local/.go/&quot;
rm -rf &quot;/usr/local/go/&quot;

These two command remove go and hidden .go files. Now we also have to update entries in shell profile.

Open your basic file. Mostly I open like this sudo gedit ~/.bashrc and remove all go mentions.

You can also do by sed command in ubuntu

sed -i &#39;/# GoLang/d&#39; .bashrc
sed -i &#39;/export GOROOT/d&#39; .bashrc
sed -i &#39;/:$GOROOT/d&#39; .bashrc
sed -i &#39;/export GOPATH/d&#39; .bashrc
sed -i &#39;/:$GOPATH/d&#39; .bashrc

It will remove Golang from everywhere. Also run this after running these command

source ~/.bash_profile

Tested on linux 18.04 also. That's All.

答案14

得分: -3

  1. 进入目录

    cd /usr/local
    
  2. 使用超级用户权限删除它

    sudo rm -rf go
    
英文:
  1. Go to the directory

    cd /usr/local
    
  2. Remove it with super user privileges

    sudo rm -rf go
    

答案15

得分: -3

只有rm -rvf /usr/local/go/这个命令不起作用,但是sudo rm -rvf /usr/local/go/可以正常工作。

英文:

only tab
rm -rvf /usr/local/go/
not works well, but
sudo rm -rvf /usr/local/go/
do.

huangapple
  • 本文由 发表于 2017年2月12日 17:29:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/42186003.html
匿名

发表评论

匿名网友

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

确定