如何使“godoc”命令在我的系统上工作?

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

How to make "godoc" command work on my system?

问题

"godoc"在我的系统上无法工作。(我使用的是ubuntu 13.04)

godoc fmt

会给出以下错误

2013/06/08 19:12:43 readTemplate: open /usr/lib/go/lib/godoc/codewalk.html: no such file or directory

"which go"给出的结果是:

/usr/bin/go

"go env"给出的结果是:

GOROOT="/usr/lib/go"
GOBIN=""
GOARCH="386"
GOCHAR="8"
GOOS="linux"
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_386"
GOGCCFLAGS="-g -O2 -fPIC -m32 -pthread"
CGO_ENABLED="1"

我应该怎么做才能让它工作?

英文:

"godoc" doesnt' work on my system.(I'm using ubuntu 13.04)

godoc fmt

gives the following error

2013/06/08 19:12:43 readTemplate: open /usr/lib/go/lib/godoc/codewalk.html: no such file or directory

"which go" gives:

/usr/bin/go

"go env" gives the following:

GOROOT="/usr/lib/go"
GOBIN=""
GOARCH="386"
GOCHAR="8"
GOOS="linux"
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_386"
GOGCCFLAGS="-g -O2 -fPIC -m32 -pthread"
CGO_ENABLED="1"

What should I do to make it work?

答案1

得分: 74

go install -v golang.org/x/tools/cmd/godoc@latest

英文:

Install godoc by using go install

go install -v golang.org/x/tools/cmd/godoc@latest

答案2

得分: 25

正如其他人指出的那样,Go 1.2中的一些更改导致Debian软件包维护者进行了一些更改。目前安装godoc的方法是:

sudo apt-get install golang-go.tools

这是因为Go开发人员将godoc从正常分发中移出,并放入go.tools子存储库中。这个子存储库更新更频繁,并且有不同的向后兼容规则。

英文:

As has been pointed out by others some changes in Go 1.2 have caused the debian package maintainers to make some changes. The current way to install godoc is

sudo apt-get install golang-go.tools

This is because the Go developers moved godoc out of the normal distribution and into the go.tools subrepo. This subrepo is updated more frequently and has different rules for backwards compatibility.



Old answer:

It looks like you installed from the ubuntu package. You need to install golang-doc package in order to use godoc. This is installed automatically if you install the golang metapackage.

sudo apt-get install golang

If you use packages to install Go, I also recommend installing from the gophers PPA. Current packages are very old. The current is 1.0.2 when 1.0.3 was the final 1.0 release and 1.1 is the current version number. Details can be found at https://wiki.ubuntu.com/Go.

答案3

得分: 19

最简单的方法

  1. 首先,使用以下命令安装godoc

    go get golang.org/x/tools/cmd/godoc
    
  2. 启动godoc服务器:

    godoc -http=:6060
    
  3. 在浏览器中访问:

    http://localhost:6060
    
英文:

Simplest way:

  1. First, install godoc with following command:

    go get golang.org/x/tools/cmd/godoc
    
  2. Start godoc server:

    godoc -http=:6060
    
  3. In your browser, visit:

    http://localhost:6060
    

答案4

得分: 13

以下是我在Ubuntu 13.10上的解决方法:

sudo apt-get install golang-doc
godoc -http=:6060

导航至 http://localhost:6060


编辑:随发行版一起提供的版本可能已过时。我目前不是一个活跃的Go用户,但是这个答案看起来是最完整的:https://stackoverflow.com/a/61300854/15985

英文:

The following worked for me on Ubuntu 13.10:

sudo apt-get install golang-doc
godoc -http=:6060

Navigate to http://localhost:6060


EDIT: The version shipped with the distribution is likely to be out of date. I'm not an active Go user at the moment but this answer looks the most complete: https://stackoverflow.com/a/61300854/15985

答案5

得分: 9

你需要安装golang-go.tools软件包。

sudo apt-get install golang-go.tools

英文:

You need to install the golang-go.tools package.

sudo apt-get install golang-go.tools

答案6

得分: 3

在Ubuntu 14.04中,需要安装golanggolang-docgolang-go.tools

sudo apt-get update
sudo apt-get install golang
sudo apt-get install golang-doc
sudo apt-get install golang-go.tools

然后运行以下命令来使用:

godoc -http=:6060 

在浏览器中打开localhost:6060

英文:

in ubuntu 14.04 have to install golang,golang-doc and golang-go.tools :

sudo apt-get update
sudo apt-get install golang
sudo apt-get install golang-doc
sudo apt-get install golang-go.tools

and for use, run :

godoc -http=:6060 

and open localhost:6060 in your browser.

答案7

得分: 2

你可以使用sudo apt install golang-golang-x-tools在Ubuntu上安装go doc。

英文:

You can use sudo apt install golang-golang-x-tools to install go doc on ubuntu.

答案8

得分: 1

首先卸载golang

apt-get purge golang*

从https://golang.org/dl/下载编译好的go存档

wget https://storage.googleapis.com/golang/go1.7.3.linux-amd64.tar.gz
tar -xvf go1.6.linux-amd64.tar.gz
mv go /usr/local

不过,mv命令并不是必需的。你可以创建一个指向你的go安装目录的符号链接/usr/local/go

sudo ln -s $GO_HOME /usr/local/go

你可能需要设置Go路径。然后你可以测试你的安装。

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

现在应该可以使用godoc了。

英文:

First uninstall golang

apt-get purge golang*

Download compiled go archive from https://golang.org/dl/

wget https://storage.googleapis.com/golang/go1.7.3.linux-amd64.tar.gz
tar -xvf go1.6.linux-amd64.tar.gz
mv go /usr/local

The mving is not really necessary, though. You could just create a symlink /usr/local/go pointing to your go installation directory.

sudo ln -s $GO_HOME /usr/local/go

You may need to set Go Paths. Then you can test your install.

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

godoc should be usable now.

答案9

得分: 1

这对我有用(我更喜欢手动在/usr/local/go中安装Go):

$ sudo -i
root# unset GOPATH
root# go get golang.org/x/tools/cmd/godoc
root# which godoc
/usr/local/go/bin/godoc

干杯!

英文:

This worked for me (I prefer to install Go by hand in /usr/local/go):

$ sudo -i
root# unset GOPATH
root# go get golang.org/x/tools/cmd/godoc
root# which godoc
/usr/local/go/bin/godoc

Cheers!

答案10

得分: 0

对于Fedora:

sudo dnf install golang-godoc

godoc -http=localhost:8080

英文:

For Fedora:

sudo dnf install golang-godoc

godoc -http=localhost:8080

答案11

得分: 0

我已经安装了go,但是我没有godoc,但是我看到了:
go doc fmt

(go doc - 我从go help中看到的)

英文:

I've installed go and also havn't godoc, but I see:
go doc fmt

(go doc - I see from go help)

huangapple
  • 本文由 发表于 2013年6月8日 22:35:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/17000548.html
匿名

发表评论

匿名网友

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

确定