I have used Golang some years ago, but unfortunately I hadn't tried to do it in a long time and had forgotten all about it....
So I set it up from the beginning with a fresh mind.😊
The environment I used is as follows.
- macOS Catalina 10.15.5
- Visual Studio Code 1.46.1
Installing Go
Download and install Go from the following link.
After the installation, open a terminal and check the version using the following command.
$ go version
go version go1.15.2 darwin/amd64
Create directory for GOPATH setting.
$ mkdir ~/go
For GOPATH envirionment variable, add the following lines to the ~/.bash_profile
.
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$PATH
Installing Visual Studio Code
Download and install VSCode from the following link.
After the installation, Launch VSCode.
Open the Extensions Marketplace (Cmd+Shift+X
), search Go
and install it.
open the Command Palette (Cmd+Shift+P
) and run the Go: Install/Update Tools
command.
Install all the Go extensions listed there.
Start coding
Create hello.go
in VSCode.
package main
import "fmt"
func main() {
fmt.Println("Hello, world!")
}
By default, auto-completion and formatting for code saving are enabled. That's great.
Open a terminal (Ctrl+`
) and execute the following command.
$ go run hello.go
Hello, world!
Have fun!👍
Top comments (12)
Thank you! Easy start for me
You're welcome!
Thanks for saving me today. I already spent 3h on this
Exactly what I needed 🚀
Thanks! 😊
How do I have the little play button in the top right like in python
Thanks, this helps
Thank you Takagi!
Thanks! 👍
Great Articles!
Thanks! Fast and straight forward.
all good, but I have no curly lines error highlighting. anyway to fix this?