Skip to main content
benhall / golang-demo
About Waitlist Learn Search Enterprise
Search
Login Sign Up
Logo
Main Menu Project Homepage Learn Codebase Developer Dashboards Contribute Extensions Help
  • Learn Codebase
  • Learn API
  • Learn SDK
  • Environment Setup
  • Knowledge Base
  • Chat to Codebase
  • Search
Logo Shoulder Homepage
Project Homepage
Learn Codebase
Developer Dashboards
Contribute
Extensions
Help
  • Development
  • Setup
  • Docker Configuration
  • Start & Build
  • Run Tests
  • Configuration
  • Common Issues
  • CI/CD
  • Workflow
  • Automation scripts
  • Deploy
  • Production
  • Deployment
  • Secret Management
  • Monitoring & Logging
  • Scaling & Performance
  • Contributor Dashboards
Cloud Setup Windows Setup MacOS Setup Linux Setup Docker Setup VS Code Setup Terminal

Installing Golang on Windows

Step 1: Download the Installer

  1. Visit the official Go download page: https://go.dev/dl/
  2. Download the Windows installer package (.msi) file. The filename will be similar to go<version>.windows-amd64.msi.

Step 2: Install Golang

  1. Run the downloaded .msi file.
  2. Follow the prompts in the installer to complete the installation.

Step 3: Verify the Installation

  1. Open the Command Prompt or PowerShell.
  2. Verify the installation by running the following command:
go version

You should see the Go version information if the installation was successful.

Step 4: Set Up the Go Environment

  1. Open the Environment Variables dialog:
  • Right-click on This PC or Computer on the desktop or in File Explorer.
  • Select Properties.
  • Click on Advanced system settings.
  • Click on the Environment Variables button.
  1. Add a new user variable:
  • Variable name: GOPATH
  • Variable value: C:\Users\<YourUsername>\go
  1. Edit the Path variable in the System variables section and add a new entry:
  • C:\Go\bin
  • %GOPATH%\bin

Installing Golang on macOS

Step 1: Download the Installer

  1. Visit the official Go download page: https://go.dev/dl/
  2. Download the macOS installer package (.pkg) file. The filename will be similar to go<version>.darwin-amd64.pkg.

Step 2: Install Golang

  1. Open the downloaded .pkg file.
  2. Follow the prompts in the installer to complete the installation.

Step 3: Verify the Installation

  1. Open the Terminal application.
  2. Verify the installation by running the following command:
go version

You should see the Go version information if the installation was successful.

Step 4: Set Up the Go Environment

  1. Open or create a .bash_profile or .zshrc file in your home directory.
  2. Add the following lines to set up the Go environment variables:
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
  1. Apply the changes by running:
source ~/.bash_profile  # or source ~/.zshrc

Installing Golang on Linux

Step 1: Download the Archive

  1. Visit the official Go download page: https://go.dev/dl/
  2. Download the Linux tarball (.tar.gz) file. The filename will be similar to go<version>.linux-amd64.tar.gz.

Step 2: Install Golang

  1. Open a Terminal window.
  2. Extract the tarball to /usr/local:
sudo tar -C /usr/local -xzf go<version>.linux-amd64.tar.gz

Step 3: Set Up the Go Environment

  1. Open or create a .bashrc or .zshrc file in your home directory.
  2. Add the following lines to set up the Go environment variables:
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
  1. Apply the changes by running:
source ~/.bashrc  # or source ~/.zshrc

Step 4: Verify the Installation

  1. Open a Terminal window.
  2. Verify the installation by running the following command:
go version

You should see the Go version information if the installation was successful.


Following these steps, you should have Golang successfully installed on macOS, Windows, and Linux. You are now ready to start developing with Go!

Installing Golang using Docker

This guide will walk you through installing and running Golang using Docker on any platform that supports Docker. This approach allows you to use Golang without having to install it directly on your system.

Prerequisites

  • Ensure Docker is installed on your machine. If Docker is not installed, you can download and install it from Docker’s official website.

Steps to Install and Run Golang with Docker

Step 1: Pull the Official Golang Docker Image

  1. Open your terminal (Command Prompt, PowerShell, or any terminal application).
  2. Pull the official Golang Docker image by running the following command:
docker pull golang

Step 2: Run a Golang Container

You can start a Golang container with a specific version or the latest version. Below are examples for both scenarios.

Running the Latest Version

  1. Run the following command to start a container with the latest version of Golang:
docker run -it --name golang-container golang

Running a Specific Version

  1. Visit the official Golang Docker Hub page to find the specific version tag you need.
  2. Run the following command, replacing <version> with your desired version (e.g., 1.16):
docker run -it --name golang-container golang:<version>

Step 3: Verify the Installation

  1. Once inside the container, verify the Golang installation by running:
go version

You should see the Go version information if the installation was successful.

Step 4: Write and Run a Simple Go Program

  1. Create a new Go file, for example, hello.go:
echo 'package main; import "fmt"; func main() { fmt.Println("Hello, Docker!") }' > hello.go
  1. Run the Go program:
go run hello.go

You should see the output:

Hello, Docker!

Step 5: Persisting Work

By default, any work done inside the container will be lost once the container is stopped and removed. To persist your work, you can mount a local directory to the container.

  1. Create a local directory to store your Go workspace, for example:
mkdir -p ~/go-workspace
  1. Run the Golang container with the local directory mounted:
docker run -it --name golang-container -v ~/go-workspace:/go golang

Now, any files created or modified within the /go directory inside the container will be reflected in your local ~/go-workspace directory.

Step 6: Stopping and Removing the Container

  1. To stop the running container, use the following command in another terminal:
docker stop golang-container
  1. To remove the container, use:
docker rm golang-container

Additional Tips

  • To list all Docker containers, run:
docker ps -a
  • To start an existing container, run:
docker start -i golang-container
  • To remove all stopped containers, run:
docker container prune

Following these steps, you should be able to install and run Golang using Docker on any system that supports Docker. This method allows you to keep your development environment clean and isolated.

VS Code Environment

When using VS Code we recommend installing the following extensions:

Golang VS Code

Go language support for Visual Studio Code.

 screenshot

Docker

Makes it easy to create, manage, and debug containerized applications.

 screenshot

CLI Tooling

The tooling CLI tooling would be beneficial to have setup:

Docker

More details coming soon

Cloud based Development Environments

No cloud-based development environments are available for this project, however use the links below to quickly launch a new environment.

Gitpod

Open in Gitpod

GitHub Codespaces

Open in GitHub Codespaces

VS Code

Open in VS Code (Web)
Shoulder.dev can make mistakes.Consider checking important information.