DEV Community

Cover image for Setting Up a Golang Development Environment
Kenta Takeuchi
Kenta Takeuchi

Posted on • Originally published at bmf-tech.com

Setting Up a Golang Development Environment

#go

This article was originally published on bmf-tech.com.

Overview

We will set up the Go environment.

Setting Up Go Environment

Installing Go

The installation method is omitted. I use a tool called anyenv for installation.

Specifying GOPATH

Specify GOPATH in .bashrc or .bash_profile.

export GOPATH=$HOME/localdev/project/go_dev // Set as you like
PATH=$PATH:$GOPATH/bin
Enter fullscreen mode Exit fullscreen mode

Checking Go Directory Structure

The directory structure in the local environment will be organized according to the official documentation.

go_dev/
├── bin
├── pkg
└── src
Enter fullscreen mode Exit fullscreen mode

A development directory for Go called go_dev is prepared, containing three directories for different roles, in accordance with the official documentation's directory structure. Executable commands are placed in bin, packages in pkg, and sources in src. The src/ directory is managed by git.

Creating a Package

As a check to see if the setup so far is successful, let's create a package.

Prepare a test/ directory in src/ and create a file called main.go as follows:

package main

import "fmt"

func main() {
    fmt.Println("Hello, 世界")
}
Enter fullscreen mode Exit fullscreen mode

Compile with go build main.go, create a binary file, and if a binary file named test is generated in bin/ with go install, you're all set.

Setting Up a Docker Development Environment

Top comments (0)