0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

「Goツアー日本語版」をMacで手軽に試す方法

Last updated at Posted at 2025-06-19

はじめに

Go言語の学習をはじめようと思い、公式チュートリアルである「A Tour of Go」に挑戦する方は多いと思います。

実はこのチュートリアルには有志の方が作成してくださっている日本語版が存在し、ローカル環境で動かすことができます。

この記事では、HomebrewでGo言語をインストール済みのMac環境を前提として、「A Tour of Go」日本語版を最も手軽に起動する手順をまとめます。

前提条件

  • macOS
  • Homebrew がインストール済み
  • brew install go などでGo言語がインストール済み
  • git コマンドが利用可能

結論:この3行で起動できる

ターミナルで以下のコマンドを順に実行すればOKです。

git clone https://github.com/atotto/go-tour-jp.git
cd go-tour-jp
go run .

実行後、自動でブラウザが立ち上がり http://localhost:3999 が開かれれば成功です。

よくある失敗例:go install

なぜ上記の git clone からの手順が必要なのでしょうか。
Goのパッケージをインストールする際によく使われる go install コマンドを試すと、私の環境ではエラーになってしまいました。

試したコマンド

go install github.com/atotto/go-tour-jp/gotour@latest

表示されるエラー

go: github.com/atotto/go-tour-jp/gotour@latest (in github.com/atotto/go-tour-jp@v0.0.0-20201205034358-913c5eae8455):
    The go.mod file for the module providing named packages contains one or
    more replace directives. It must not contain directives that would cause
    it to be interpreted differently than if it were the main module.

これは、Go 1.16以降のセキュリティ強化が理由です。
インストールしようとしているパッケージの設定ファイル (go.mod) に replace という記述が含まれている場合、安全のため go install が許可されなくなりました。

この問題を回避し、かつ最もシンプルに日本語版ツアーを起動する方法が、ソースコードを直接ダウンロードして go run で実行する方法です。

正しい手順(詳細)

改めて、手順を詳しく見ていきましょう。

1. ソースコードをダウンロードする

まず、ターミナルでお好きな作業ディレクトリに移動し、git clone コマンドで日本語版ツアーのソースコード一式をダウンロードします。

git clone https://github.com/atotto/go-tour-jp.git

2. ディレクトリを移動する

ダウンロードして作成された go-tour-jp ディレクトリに cd コマンドで移動します。

cd go-tour-jp

3. Goプログラムを実行する

go run . コマンドを実行します。
これは、カレントディレクトリにあるソースコードをコンパイルし、直接実行するコマンドです。

go run .

コマンドを実行すると、ターミナルには Serving at http://127.0.0.1:3999 のようなメッセージが表示され、自動的にブラウザが起動します。

もしブラウザが起動しない場合は、手動で http://localhost:3999 にアクセスしてください。

ツアーを終了したい場合は、ターミナルで Ctrl + C を押してください。

まとめ

go install が使えない場合でも、git clone して go run . を実行することで、簡単にローカルでプログラムを動かすことができます。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?