Member-only story
If You Are Learning Golang, Remember These 10 Commands
Go has really taken off lately. More and more companies are adopting it, and developers are generally accepting it, because it is easy to learn, yet powerful to use.
If you are currently at the beginning of your Go journey, here are 10 useful CLI commands that you will probably be using every day while working with Golang.
Before you can do anything with Go on your local machine, you need to install the Go compiler. You can check if it is already installed by running:
go version
If it’s already installed you should something like this:
go version go1.17.6 linux/amd64
If it is not installed, you can install it from here.
Next, you might want to check some environment variables related to Go, that might be useful such as GOROOT or GOPATH. You can see them by running:
go env
Now you can actually start writing code. The first command you should run at the beginning of every Go project is:
go mod init <project name>
It will initialize a go.mod file, which is something similar to a pom.xml if you are coming from Java, or package.json if you are coming from JavaScript.
Next, you want to install a certain third party library or framework which you will use in your project:
go get <package name>