# If You Are Learning Golang, Remember These 10 Commands

## Metadata
- Author: [[Pavle Djuric]]
- Full Title: If You Are Learning Golang, Remember These 10 Commands
- Category: #articles
- Summary: Go is easy to learn and many developers are using it. This article shares 10 important commands to help you start coding in Go. These commands help you install, run, test, and manage your Go projects efficiently.
- URL: https://pavledjuric.medium.com/if-you-are-learning-golang-remember-these-10-commands-44e3bc194b16
## Highlights
- 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 ([View Highlight](https://read.readwise.io/read/01k1kvdqsv40gqya98rbcvmnfs))
- Next, you might want to check some environment variables related to Go, that might be useful such as [GOROOT or GOPATH](https://www.jetbrains.com/help/go/configuring-goroot-and-gopath.html#:~:text=GOROOT%20is%20a%20variable%20that,the%20root%20of%20your%20workspace.). You can see them by running:
go env ([View Highlight](https://read.readwise.io/read/01k1kvdz0svxjxsn4ygf7ng1nv))
- 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 ([View Highlight](https://read.readwise.io/read/01k1kve7kfn03aqaqh526651xc))
- Next, you want to install a certain third party library or framework which you will use in your project:
go get <package name> ([View Highlight](https://read.readwise.io/read/01k1kveymsn2dkrekxs4erzzrc))
- You then write some Go code, and want to run it locally to see if everything works as expected:
go run . ([View Highlight](https://read.readwise.io/read/01k1kvf36pab0jt1ej7rbqatzb))
- you can compile your entire code into a single binary. The command for doing that is:
go build -o <name of binary> <packages> ([View Highlight](https://read.readwise.io/read/01k1kvfbna36w1ewc829tg3b55))
- Before pushing it to Github, you will want to format it, so your PR doesn’t get a *please format your code before merging* comment:
go fmt ([View Highlight](https://read.readwise.io/read/01k1kvfhtfp9dy9b3wr85hrqy2))
- After experimenting with a couple of frameworks, you decide to drop all of them from your code base and write everything yourself. But, your **go.mod** file still contains these unused modules. We can fix this by running:
go mod tidy
This command will remove all unused modules from your **go.mod** file, so you don’t have to manually edit this file. ([View Highlight](https://read.readwise.io/read/01k1kvfzyhk00wdpr8sp29p3d9))
- In order to run your tests simply execute:
go test ([View Highlight](https://read.readwise.io/read/01k1kvgdzxfq5n6v6dqenawajj))