blob: 6c725634e90a18285d9abd9de0cbe29d78d0228d [file] [log] [blame] [view]
Ian Lance Taylor5cf80712017-11-14 06:45:22 -08001The 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.
2
3
4- [Unix systems](#unix-systems)
5 * [Bash](#bash)
6 * [Zsh](#zsh)
7- [Windows](#windows)
8
9# Unix systems
10
11`GOPATH` can be any directory on your system. In Unix examples, we will set it to `$HOME/work`. Note that `GOPATH` must not be the same path as your Go installation. Another common setup is to set GOPATH=$HOME.
12
13## Bash
14
15Edit your `~/.bash_profile` to add the following line:
16```bash
17export GOPATH=$HOME/work
18```
19
20Save and exit your editor. Then, source your `~/.bash_profile`.
21```bash
22source ~/.bash_profile
23```
24
25> Note: Set the GOBIN path to generate a binary file when `go install` is run.
26> ```bash
27> export GOBIN=$HOME/work/bin
28> ```
29
30## Zsh
31
32Edit your `~/.zshrc` file to add the following line:
33
34```bash
35export GOPATH=$HOME/work
36```
37Save and exit your editor. Then, source your `~/.zshrc`.
38```bash
39$ source ~/.zshrc
40```
41
42# Windows
43
44Your workspace can be located wherever you like,
45but we'll use `C:\work` in this example.
46Note that `GOPATH` must not be the same path as your Go installation.
47
48* Create folder at `C:\work`.
49* Right click on "Start" and click on "Control Panel". Select "System and Security", then click on "System".
50* From the menu on the left, select the "Advanced systems settings".
51* Click the "Environment Variables" button at the bottom.
52* Click "New" from the "User variables" section.
53* Type `GOPATH` into the "Variable name" field.
54* Type `C:\work` into the "Variable value" field.
55* Click OK.