LoginSignup
3
2

More than 5 years have passed since last update.

Go言語のインストール方法 Windows10環境

Posted at

Go言語のインストール方法 Windows10環境

Go言語をはじめようと思った背景

  • 先日、サンフランシスコで開催されたGoogle Cloud Next'18に参加し、Googleの開発者目線な社風に惹かれ、そのGoogleが開発したGo言語に興味を持った。
  • 最近はインタプリタ系の言語ばかり書いていたので、コンパイラ系の言語を書きたくなった。
  • Go言語は、ハードウェアレベルの記述ができると聞き、自分の技術力向上のため勉強しようと思った。

検証環境

OS:Windows 10 Pro

Go言語のダウンロード

公式サイトへアクセスし、msiファイルをダウンロードする。

golang_download.PNG

Go言語のインストール

  1. Nextをクリック

    golang_install1.PNG

  2. 利用規約を確認し、Nextをクリック

    golang_install2.PNG

  3. インストール先を選択し、Nextをクリック

    golang_install3.PNG

  4. Installをクリック

    golang_install4.PNG

  5. インストールが完了したら、Finishをクリック

    golang_install5.PNG

以上でインストール完了。

動作確認

  1. 環境変数の設定

    私は、powershellのコマンドレットを使用しています。パスは各自で変更してください。

    $ Set-Item Env:Path "$Env:Path;C:\Go\bin\"
    $ go
    Go is a tool for managing Go source code.
    
    Usage:
    
            go command [arguments]
    
    The commands are:
    
            build       compile packages and dependencies
            clean       remove object files and cached files
            doc         show documentation for package or symbol
            env         print Go environment information
            bug         start a bug report
            fix         update packages to use new APIs
            fmt         gofmt (reformat) package sources
            generate    generate Go files by processing source
            get         download and install packages and dependencies
            install     compile and install packages and dependencies
            list        list packages
            run         compile and run Go program
            test        test packages
            tool        run specified go tool
            version     print Go version
            vet         report likely mistakes in packages
    
    Use "go help [command]" for more information about a command.
    
    Additional help topics:
    
            c           calling between Go and C
            buildmode   build modes
            cache       build and test caching
            filetype    file types
            gopath      GOPATH environment variable
            environment environment variables
            importpath  import path syntax
            packages    package lists
            testflag    testing flags
            testfunc    testing functions
    
    Use "go help [topic]" for more information about that topic.
    
  2. サンプルコードの作成

    任意のフォルダに、hello.goファイルを以下の内容で作成する。

    hello.go
    package main
    
    import "fmt"
    
    func main() {
        fmt.Printf("hello, world\n")
    }
    
  3. buildの実行

    buildが終わると、hello.exeファイルが生成されます。

    $ ls
    hello
    $ cd hello
    $ cat hello.go
    package main
    
    import "fmt"
    
    func main() {
            fmt.Printf("hello, world\n")
    }
    $ hello build
    $ ls
    
        ディレクトリ: C:\Go言語\hello
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    -a----       2018/08/04      8:54        2058752 hello.exe
    -a----       2018/08/04      8:54             79 hello.go
    
  4. hello.exeの実行

    $ .\hello.exe
    hello, world
    

    以上で無事Go言語のインストールが終了しました。

今後

Golangの書き方等も今後更新する予定です。
Google Cloud Next'18に関してもなにか書きたいと思います。

3
2
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
3
2