【发布时间】:2015-07-17 20:21:25
【问题描述】:
我在我的 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"
【问题讨论】:
-
为什么不直接用 apt-get 安装呢? github.com/golang/go/wiki/Ubuntu
-
@OneOfOne 我做了,但我遇到了另一个问题。我再试一次,用这个问题更新我的问题
-
我不确定,但如果你在官方包中遇到这个错误,你应该提交一个错误。
-
不要使用 apt-get。版本太过时了。看看github.com/moovweb/gvm
-
感谢大家的帮助。我最终彻底清除了外出,然后使用@elithrar 发布的脚本进行安装,它现在可以工作了!
标签: ubuntu go installation