gpt4 book ai didi

ubuntu - 在 Ubuntu 上正确安装 Go 时遇到问题

转载 作者:IT老高 更新时间:2023-10-28 13:10:25 25 4
gpt4 key购买 nike

我在我的 Mac 上成功安装了这个,只是在 Linux 上遇到了问题。我正在关注他们的文档 https://golang.org/doc/install .我正在运行一台 64 位机器,所以我下载了 64 位存档。下载后我运行

sudo tar -C /usr/local/ -xzf ~/Downloads/go1.4.2.linux-amd64.tar.gz

我在我的主文件夹中创建了一个 go 目录。我有结构

/home
--/chrism
----/go
------/src
------/pkg
------/bin

我将以下内容添加到 /etc/profile。保存后我运行 source/etc/profile

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

src/ 我添加了一个目录 git.mycompany.com 并在他们的另一个名为 test 的目录中。在 test/ 我制作了 test.go 并将上面教程中的代码块粘贴到

package main

import "fmt"

func main() {
fmt.Printf("hello, world\n")
}

当我运行 go run test.go 时,它会输出以下内容

chrism@ubuntu:~/go/src/git.mycompany.com/test$ go run test.go 
# fmt
Usage: pack op file.a [name....]
Where op is one of cprtx optionally followed by v for verbose output.
For compatibility with old Go build environments the op string grc is
accepted as a synonym for c.

For more information, run
godoc cmd/pack
# runtime
Usage: pack op file.a [name....]
Where op is one of cprtx optionally followed by v for verbose output.
For compatibility with old Go build environments the op string grc is
accepted as a synonym for c.

For more information, run
godoc cmd/pack

如果我在导入语句中添加更多包,它也会输出所有这些包的文档。

编辑 0:我还尝试使用 apt-get 进行安装。我卸载并删除了我以前的更改,然后安装。这导致运行时出现以下情况:

chrism@ubuntu:~/go/src/git.mycompany.com/test$ go run test.go 
go build fmt: exec: "/usr/local/go/pkg/tool/linux_amd64/pack": stat /usr/local/go/pkg/tool/linux_amd64/pack: no such file or directory
go build runtime: exec: "/usr/local/go/pkg/tool/linux_amd64/pack": stat /usr/local/go/pkg/tool/linux_amd64/pack: no such file or directory

编辑 1:这是运行 go env

的输出
GOROOT="/usr/lib/go"
GOBIN=""
GOARCH="amd64"
GOCHAR="6"
GOOS="linux"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CGO_ENABLED="1"

最佳答案

这些是我在 Ubuntu 系统中安装 Go 所遵循的步骤:

短版:1. 运行以下命令进行安装:

sudo apt-get remove -y gccgo-go && wget http://golang.org/dl/go1.8.linux-amd64.tar.gz && sudo apt-get -y install gcc && sudo tar -C /usr/local -xzf go1.8.2.linux-amd64.tar.gz && echo "export PATH=\$PATH:/usr/local/go/bin" >> ~/.bashrc

Note: Changes the version number to install a specific version of Go. For example, to install 1.9 instead of 1.8 change the file name to go1.9.linux-amd64.tar.gz. The latest Go distributions can always be found at the official Go downloads page

  1. 设置工作场所。 (第 6 点)

加长版:

  1. here 下载二进制版本.对 ubuntu 使用 go x.x.x.linux-amd64.tar.gz。对于 1.4.2 版本,您可以在终端中键入以下内容。

    wget http://golang.org/dl/go1.8.linux-amd64.tar.gz
  2. 为 cgo 安装 gcc

    sudo apt-get install gcc 
  3. 在/usr/local 中解压压缩包。它应该创建一个 go 目录。

    tar -C /usr/local -xzf go1.8.linux-amd64.tar.gz

    (通常这些命​​令必须以 root 身份或通过 sudo 运行。)

  4. 将/usr/local/go/bin 添加到 PATH 环境变量中。

    gksu gedit ~/.bashrc
  5. 在文件末尾添加以下行

    export PATH=$PATH:/usr/local/go/bin
  6. 设置工作区

    一个。在您的首选位置创建一个工作区目录名称 go(除非您使用默认的 go 安装位置)。我正在使用/home/vembu/work/projects/go

    mkdir -p /home/vembu/work/projects/go

    b.导出 GOPATH

    gedit ~/.bashrc

    c。在倒数第二行添加以下行

    export GOPATH=/home/vembu/work/projects/go

    d。为方便起见,将工作区的 bin 子目录添加到 PATH:

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

    e。最后.bashrc的最后两行应该是这样的

    export GOPATH=/home/vembu/work/projects/go
    export PATH=/usr/local/go/bin:$GOPATH/bin:$PATH

    f。重启终端。

关于ubuntu - 在 Ubuntu 上正确安装 Go 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31484085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com