0
0

More than 1 year has passed since last update.

ローカル(VirtualBox)でのGo実行環境構築

Last updated at Posted at 2023-03-31

作業環境

項目
仮想OS Amazon Linux2
CPU 2 Core
実装RAM 2 GB
Disk 25 GB

必要なツール

  • SSH接続できるもの(Teratarm,Putty,Rloginとかなんでも)
  • Virtualbox + Vagrant で構築した仮想環境

必要な知識

  • Linux操作に対する知見

対象リソース

golang 1.18.9-1.amzn2.0.1

作業内容

  • 対象環境へのログイン
  • Goのインストール
  • Goを使ってみる

作業開始

対象環境へのログイン

  1. Vagrantfileのある作業フォルダでGitbashを起動する。
  2. ログイン先確認
    $ vagrant global-status
    
  3. 仮想マシンの起動
    $ vagrant ssh
    
  4. 特権への切り替え
    $ sudo su -
    
  5. packageのアップデート
    # yum update -y
    # yum upgrade -y
    

Golangのインストール

  1. インストール
    # yum install golang -y
    
  2. バージョン確認
    # go version
    go version go1.18.9 linux/amd64
    

Goを使ってみる

Go公式チュートリアルの手順を実施してみる。

  1. 作業フォルダの作成

    # mkdir -p ./work/hello && cd ./work/hello
    
  2. Goモジュールを作る

    # go mod init example/hello
    # vi hello.go
    # cat hello.go
    package main
    
    import "fmt"
    
    func main() {
      fmt.Println("Hello, World!")
    }
    
  3. GOを実行する

    # go run .
    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