In this tutorial we have three things we want to learn, how:
- To downlaod and install Go Programming Language.
- Download and Install VS Code and a few extensions.
- Write and run hello world in Go.
Here's our video tutorial:
Step 1: Download and Install Go
- Head over to https://golang.org/dl/.
- Download Go based in your Operating system.
- Install it:
For Windows
-
Open the MSI file you downloaded and follow the prompts to install Go.
By default, the installer will install Go to
Program Files
orProgram Files (x86)
. You can change the location as needed. After installing, you will need to close and reopen any open command prompts so that changes to the environment made by the installer are reflected at the command prompt. -
Verify that you've installed Go.
- In Windows, click the Start menu.
- In the menu's search box, type
cmd
, then press the Enter key. - In the Command Prompt window that appears, type the following command:
$ go version
- Confirm that the command prints the installed version of Go.
For Linux
-
Extract the archive you downloaded into /usr/local, creating a Go tree in /usr/local/go.
Important: This step will remove a previous installation at /usr/local/go, if any, prior to extracting. Please back up any data before proceeding.
For example, run the following as root or through
sudo
:rm -rf /usr/local/go && tar -C /usr/local -xzf go1.16.5.linux-amd64.tar.gz
-
Add /usr/local/go/bin to the
PATH
environment variable.You can do this by adding the following line to your $HOME/.profile or /etc/profile (for a system-wide installation):
export PATH=$PATH:/usr/local/go/bin
Note: Changes made to a profile file may not apply until the next time you log into your computer. To apply the changes immediately, just run the shell commands directly or execute them from the profile using a command such as
source $HOME/.profile
. -
Verify that you've installed Go by opening a command prompt and typing the following command:
$ go version
-
Confirm that the command prints the installed version of Go.
For Mac
-
Open the package file you downloaded and follow the prompts to install Go.
The package installs the Go distribution to /usr/local/go. The package should put the /usr/local/go/bin directory in your
PATH
environment variable. You may need to restart any open Terminal sessions for the change to take effect. -
Verify that you've installed Go by opening a command prompt and typing the following command:
$ go version
-
Confirm that the command prints the installed version of Go.
Step 2: Download and Install VSCode
Visual Studio Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, macOS and Linux.
Head over to https://code.visualstudio.com/download and download and install the VS Code.
Then install two vs code extensions:
- Go Language support.
- code runner.
How? Well follow the following instructions:
- Open Visual Studio code.
- Go Menu -> View - Extensions.
- Search
Go
and install Go Language support. - Search
Code Runner
and install it. - Reload your editor.
Step 3: Write Hello World in Go
Create a file named hello.go
.
Paste the following code:
package main
import "fmt"
func main() {
fmt.Println("Hello, World People")
}
Run and you will get the following
Hello, World People
That's it.