How to Setup Golang Development Environment on Ubuntu

How to Setup Golang Development Environment on Ubuntu

Bitnesia Development Mar 25, 2026 112 ID

Go, also known as Golang, is an open-source programming language developed by Google. Golang is popular for its high performance, simple syntax, and strong support for building network-based applications, distributed systems, and microservices. In this article, we will cover the steps to set up a Golang development environment on Ubuntu, including mkcert + Caddy for local HTTPS reverse proxy with the domain myapp.local, Git integration for version control, and Visual Studio Code as the main editor.

1. Install Golang

Install Golang from the Ubuntu repository:

sudo apt install golang -y

Check the version:

go version

If you want the latest version, download it from go.dev/dl, then extract it to /usr/local/go:

wget https://go.dev/dl/go1.25.0.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.25.0.linux-amd64.tar.gz

Add Go to your environment path:

echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrc

2. Creating a Golang Program

Create a project directory:

mkdir -p ~/go/myapp
cd ~/go/myapp

Create a main.go file:

package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Success! Golang application with local HTTPS is running")
}

func main() {
    http.HandleFunc("/", handler)

    fmt.Println("Server is running at http://localhost:8080")
    fmt.Println("If Caddy is configured, access via https://myapp.local")

    // Run server
    err := http.ListenAndServe(":8080", nil)
    if err != nil {
        fmt.Println("Error while running server:", err)
    }
}

Run the application:

go run main.go

3. Install Caddy

Install Caddy for reverse proxy:

sudo mkdir -p /usr/share/keyrings

curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \
  | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/caddy-stable-archive-keyring.gpg] \
https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main" \
  | sudo tee /etc/apt/sources.list.d/caddy-stable.list

sudo apt update
sudo apt install caddy -y

Install mkcert for local SSL:

sudo apt install libnss3-tools mkcert -y

Generate local certificates:

mkcert -install
mkcert myapp.local
sudo mv *.pem /etc/caddy
sudo chown caddy:caddy /etc/caddy/*.pem

The files myapp.local.pem and myapp.local-key.pem will be created.

4. Configure Local Domain

Edit /etc/hosts:

sudo nano /etc/hosts

Add:

127.0.0.1 myapp.local

Configure Caddyfile:

sudo nano /etc/caddy/Caddyfile

Insert the configuration:

myapp.local {
  reverse_proxy localhost:8080
  tls /etc/caddy/myapp.local.pem /etc/caddy/myapp.local-key.pem
}

Restart Caddy:

sudo systemctl restart caddy

Now open https://myapp.local in your browser.

5. Install Git

Install Git for project version control:

sudo apt install git -y
git --version

Configure identity:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Initialize the repository in your project:

cd ~/go/myapp
git init
git add .
git commit -m "Initial Golang project setup"

6. Install Visual Studio Code

Install VS Code:

wget 'https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-x64' -O code.deb
sudo dpkg -i code.deb
sudo apt install -f

To improve productivity, install the following extensions (Ctrl+Shift+X → search → Install):

code --install-extension golang.go
code --install-extension eamodio.gitlens

Or open Visual Studio Code and install:

  • Go (by Go Team at Google)
  • GitLens (for better Git integration)

Open the project in Visual Studio Code:

code ~/go/myapp

With these steps, you now have a complete Golang development environment on Ubuntu:

  • Go installed and able to run applications,
  • mkcert + Caddy for local HTTPS with the domain myapp.local,
  • Git for version control,
  • Visual Studio Code for development with Go support.

This setup gives you a development workflow similar to production while remaining safe and local.

I love keeping these tutorials free for everyone. If you've saved time or learned something new today, consider making a small donation to keep this site ad-free.

Support Free Content

Related Posts