0
0

More than 3 years have passed since last update.

【Go言語】インストールからHello worldまで

Last updated at Posted at 2020-01-31

今更感ですが、Go言語を習得しようと思い立ったので、自学習にアウトプットしていおきます。
ちなみに、開発環境は「Mac」です。

Go言語とは

3行で説明すると

  • 2009年Googleが作ったプログラム言語
  • 親はC言語、静的型付けのコンパイル言語
  • フリーかつオープンソース

対応OS

  • Linux / FreeBSD
  • Mac OS X
  • Windows

※2020/01時点

Go言語のインストール

インストール

brew install go

インストールした場所の確認

which go

インストールしたバージョンの確認

go version

Hello worldを表示するプログラムの実装

ファイルを作成

touch hello_world.go

ファイルを編集

vim hello_world.go
package main

import "fmt"

func main() {
  fmt.Printf("Hello World\n")
}

FYI. fmt パッケージ - golang.jp

fmtパッケージは、フォーマットI/Oを実装しており、C言語のprintfおよびscanfと似た関数を持ちます。フォーマットの「書式」はC言語から派生していますが、より単純化されています。

プログラムをビルドする

go build hello_world.go

直接プログラムファイルを実行

go run hello_world.go

コンパイルしたファイルを実行

hello_world
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