This program will print “hello, world” if it successfully runs, which will indicate that Go programs are compiling correctly. Save and close the file, then compile it by invoking the Go command install:

go install github.com/user/hello
Next, you can create a simple “Hello World” Go file.

nano ~/work/src/github.com/user/hello/hello.go
Then, create a directory hierarchy in this folder through this command in order for you to create your test file. You can replace the value user with your GitHub username if you plan to use Git to commit and store your Go code on GitHub. If you do not plan to use GitHub to store and manage your code, your folder structure could be something different, like ~/my_project.

mkdir -p work/src/github.com/user/hello
Create a new directory for your Go workspace, which is where Go will build its files:

mkdir $HOME/work
Inside your editor, paste the code below, which uses the main Go packages, imports the formatted IO content component, and sets a new function to print “Hello, World” when run.

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}
If that command returns “hello, world”, then Go is successfully installed and functional. You can see where the compiled hello binary is installed by using the which command:

which hello
With the file compiled, you can run it by simply executing the command:

hello
You should see output similar to this:

Outputdrwxr-xr-x 4 root root  4096 Apr  5 00:43 ./
drwxr-xr-x 3 root root  4096 Apr  5 00:43 ../
drwxr-xr-x 8 root root  4096 Apr  5 00:43 .git/
-rwxr-xr-x 1 root root     8 Apr  5 00:43 .gitignore*
-rw-r--r-- 1 root root    61 Apr  5 00:43 .travis.yml
-rw-r--r-- 1 root root  2808 Apr  5 00:43 CHANGELOG.md
-rw-r--r-- 1 root root  1851 Apr  5 00:43 CONTRIBUTING.md
.
.
.
-rw-r--r-- 1 root root  4893 Apr  5 00:43 vpcs.go
-rw-r--r-- 1 root root  4091 Apr  5 00:43 vpcs_test.go

Recommend

How To Install Go on Ubuntu 18.04 Step 3 — Testing Your Install

How To Install Go on Ubuntu 18.04 Step 2 — Setting Go Paths

How To Install Go on Ubuntu 18.04 Step 1 — Installing Go

A Fetch API Primer Fetch + Async/Await

A Fetch API Primer Error Handling

A Fetch API Primer Post, Put and Delete Requests

A Fetch API Primer Get Requests

Cómo crear un paquete y publicar una aplicación de Snap en Ubuntu 18.04 Paso 6: Publicar su Snap

Cómo crear un paquete y publicar una aplicación de Snap en Ubuntu 18.04 Paso 5: Compilar y probar su aplicación Snap

Cómo crear un paquete y publicar una aplicación de Snap en Ubuntu 18.04 Paso 3: Definir la configuración y los metadatos para su Snap

Cómo crear un paquete y publicar una aplicación de Snap en Ubuntu 18.04 Paso 2: Instalar Snapcraft

Cómo crear un paquete y publicar una aplicación de Snap en Ubuntu 18.04 Paso 1: Preparar su aplicación para agregarla a un paquete

How To Install and Use Docker Compose on Ubuntu 14.04 Conclusion Want to learn more? Join the DigitalOcean Community! Still looking for an answer?

How To Install and Use Docker Compose on Ubuntu 14.04 Step 5 — Accessing the Docker Container Filesystem (Optional)

How To Install and Use Docker Compose on Ubuntu 14.04 Step 4 — Learning Docker Compose Commands

How To Install and Use Docker Compose on Ubuntu 14.04 Step 3 — Running a Container with Docker Compose

How To Install and Use Docker Compose on Ubuntu 14.04 Step 2 — Installing Docker Compose

How To Install and Use Docker Compose on Ubuntu 14.04 Step 1 — Installing Docker

How To Build a Neural Network to Translate Sign Language into English Step 5 — Linking the Camera Feed

How To Build a Neural Network to Translate Sign Language into English Step 4 — Evaluating the Sign Language Classifier

How To Build a Neural Network to Translate Sign Language into English Step 3 — Building and Training the Sign Language Classifier Using Deep Learning

How To Build a Neural Network to Translate Sign Language into English Step 2 — Preparing the Sign Language Classification Dataset

How To Build a Neural Network to Translate Sign Language into English Step 1 — Creating the Project and Installing Dependencies