Dev In The Mountain Header
A Developer In The mountains having fun

Install

  1. Download and install the Go distribution for your platform from the official website (https://golang.org/). This will install the Go compiler and tools on your system.

  2. Set the GOPATH environment variable. This variable tells Go where to find your workspace, which is a directory where you will store your Go code. On Windows, you can set the GOPATH variable by going to Control Panel > System and Security > System > Advanced System Settings > Environment Variables, and then adding a new user or system variable. On macOS or Linux, you can set the GOPATH variable by adding a line to your .bashrc or .bash_profile file, like this: export GOPATH=$HOME/go.

  3. (Optional) Add the Go bin directory to your PATH. This will allow you to run Go commands from any directory. On Windows, you can do this by adding ;%GOPATH%\bin to the end of the PATH variable. On macOS or Linux, you can do this by adding :$GOPATH/bin to the end of the PATH variable.

  4. Test your installation by opening a terminal or command prompt and running the go command. If Go is installed correctly, you should see a list of available subcommands.

  5. Create a workspace directory and set up your Go project. To do this, create a new directory for your project, and then create a src subdirectory inside it. This will be the root of your Go workspace. You can then create a new Go package by creating a new directory inside the src directory, and adding a main.go file with some Go code.

Setting up a new Go project

  1. create a new directory for your project mkdir newproj
  2. change into that directory. cd newproj
  3. initialize the module with go mod init This will create a go.mod file in your project directory, which defines the dependencies of your project.
  4. create a new file with a go extention (main.go by convention)
  5. write your code

for example:

package main

import "fmt"

func main() {
    fmt.Println("Hello, world!")
}

More places to find me
Mental Health
follow me on Mastodon