add instructions using go env -w

Bryan C. Mills 2019-09-24 09:25:00 -04:00
parent 153f5ca388
commit 4fa62111dd

@ -3,15 +3,25 @@
The `GOPATH` environment variable specifies the location of your workspace. If no `GOPATH` is set, it is assumed to be `$HOME/go` on Unix systems and `%USERPROFILE%\go` on Windows. If you want to use a custom location as your workspace, you can set the `GOPATH` environment variable. This page explains how to set this variable on various platforms.
- [Unix systems](#unix-systems)
* [Go 1.13](#go-113)
* [Bash](#bash)
* [Zsh](#zsh)
* [fish](#fish)
- [Windows](#windows)
* [Go 1.13](#go-113-command-line)
* [Windows 10 (GUI)](#windows-10-gui)
* [Windows 10 (command line)](#windows-10-command-line)
# Unix systems
`GOPATH` can be any directory on your system. In Unix examples, we will set it to `$HOME/go` (the default since Go 1.8). Note that `GOPATH` must not be the same path as your Go installation. Another common setup is to set `GOPATH=$HOME`.
## Go 1.13
```bash
go env -w GOPATH=$HOME/go
```
## Bash
Edit your `~/.bash_profile` to add the following line:
@ -62,13 +72,17 @@ __NOTE:__ `GOPATH` must not be the same path as your Go installation.
* Type `C:\go-work` into the "Variable value" field.
* Click OK.
## Windows 10
## Go 1.13 (command line)
* Open a command prompt (`Win` + `r` then type `cmd`) or a powershell window (`Win` + `i`).
* Type `go env -w GOPATH=c:\go-work`.
## Windows 10 (GUI)
There is a faster way to edit `Environment Variables` via search:
* Left click on "Search" and type `env` or `environment`.
* Select "Edit environment variables for your account".
* ... and follow steps above.
## Windows 10 (cli version)
* Open a command prompt (windows-key + r then type "cmd") or a powershell window (windows-key + i)
* Type `setx GOPATH %USERPROFILE%\go` (this will set the `GOPATH` to your `[home folder]\go` e.g. `C:\Users\yourusername\go`
* Close the command or powershell window (the environment variable is only available for new command or powershell windows, not for the current window).
## Windows 10 (command line)
* Open a command prompt (`Win` + `r` then type `cmd`) or a powershell window (`Win` + `i`).
* Type `setx GOPATH %USERPROFILE%\go`. (This will set the `GOPATH` to your `[home folder]\go`, such as `C:\Users\yourusername\go`.)
* Close the command or powershell window. (The environment variable is only available for new command or powershell windows, not for the current window.)