lelelemon’s blog

カメの歩みでのんびり学んでいます。

【Go言語】A Tour Of Go (日本語版) のローカル実行エラー

この記事について

日本語版の A Tour Of Go  に記述のある通り、下記のコマンドでチュートリアルを実行しようとしたところ、

go tool tour

 

下記のエラーとなり、そのときの対応メモです。

go tool tour
go: no such tool "tour"

 

対応内容

同ページ内に下記の手動インストールの記載があったので、まずはこれを試してみた。

上記のコマンドの実行に問題がある場合は手動でこのツアーをインストールして実行できます:

go get github.com/atotto/go-tour-jp/gotour
gotour

 

すると今度は下記のエラー。

go get github.com/atotto/go-tour-jp/gotour
go: go.mod file not found in current directory or any parent directory.
        'go get' is no longer supported outside a module.
        To build and install a command, use 'go install' with a version,
        like 'go install example.com/cmd@latest'
        For more information, see https://golang.org/doc/go-get-install-deprecation
        or run 'go help get' or 'go help install'.

 

go install を使えとのことですが、「example.com/cmd@latest」の部分に何を指定すれば良いかわからず。

英語版の A Tour Of Go には下記が記載されていたので、これを実行してみました。

go install golang.org/x/website/tour@latest

 

これだとうまくダウンロードされ、カレントフォルダに「go」フォルダがダウンロードされ、

その中の bin フォルダに tour という実行可能ファイルが入っているので、

これを実行することでブラウザからアクセスできるようになるようです。

 

./tour
2024/01/01 20:26:13 Serving content from /root/go/pkg/mod/golang.org/x/website/tour@v0.0.0-20210616181959-e0d934b43647
2024/01/01 20:26:13 Please open your web browser and visit http://127.0.0.1:3999
2024/01/01 20:26:25 accepting connection from: 127.0.0.1:47806

 

試しに「http://127.0.0.1:3999/」にアクセス。

チュートリアルができるようになった。。

 

参考情報

macでa tour of goをローカルで実行したときに詰まった #Mac - Qiita