

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Packages
incomplete
2: Package Naming
incomplete
3: Install
incomplete
4: Modules
incomplete
5: Go Environment
incomplete
6: First Local Program
incomplete
7: Go Run
incomplete
8: Go Build
incomplete
9: Go Install
incomplete
10: Custom Package
incomplete
11: Custom Package Continued
incomplete
12: Remote Packages
incomplete
13: Clean Packages
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Let's clear up a few points before you start writing Go locally.
To recap how packages and modules work in your project directory structure:
The path to a package's directory determines its import path and where it can be downloaded from if you decide to host it on a remote version control system like GitHub or GitLab.
The $GOPATH environment variable will be set by default somewhere on your machine (typically in the home directory, ~/go). Since we will be working in the new "Go modules" setup, you don't need to worry about that. If you read something online about setting up your GOPATH, that documentation is probably out of date.
These days you should avoid storing your projects in $GOPATH. Again, that's the old way of doing things and can cause unexpected issues, so better to just avoid it.
Navigate to a location on your machine where you want to store some code. For example, I store all my code in ~/workspace, then organize it into subfolders based on the remote location. For example,
~/workspace/github.com/wagslane/go-password-validator = https://github.com/wagslane/go-password-validator
That said, you can put your code wherever you want.