Go WSLのUbuntuにGoをインストールする

More than 1 year has passed since last update.
  • WSLのUbuntuにGoをインストールする
    • Ubuntu 16.04.4 LTS
    • Go 1.10

手順

  • go/wiki/Ubuntu通りでOK

  • 以下だと1.6がインストールされる

    $ sudo apt-get install golang-go
    
  • 以下を実行する

    $ sudo add-apt-repository ppa:gophers/archive
    $ sudo apt-get update
    $ sudo apt-get install golang-1.10-go
    
  • 環境変数・PATH

    • ファイルに追記
    .zprofile
    export GOPATH=$HOME/go
    export PATH=$PATH:/usr/lib/go-1.10/bin
    export PATH=$PATH:$GOPATH/bin
    
    • シェル再ログイン
    $ exec $SHELL -l
    
  • 確認

    $ go version
    $ go env
    

動作確認

  • Test your installationを実施する

  • フォルダの作成 (仮でWindowsのデスクトップに作る)

    $ cd /mnt/c/Users/hoge/Desktop
    $ mkdir go-test
    $ cd go-test
    $ vim hello.go
    
  • ソース

    hello.go
    package main
    
    import "fmt"
    
    func main() {
        fmt.Printf("hello, world\n")
    }
    
  • ビルド & 実行

    $ go build hello.go
    $ ./hello
    

参考

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away