How to properly set GOPATH in Ubuntu and which file to edit?
Hello everyone! I just started learning Go on Ubuntu 22.04. I installed Go via apt, but when trying to run a simple program with an import of a third-party package (e.g., `github.com/gorilla/mux`), I get an error:
```
go: cannot find main module; see 'go help modules'
```
I read that I need to set the GOPATH environment variable. On Windows, this is done through system variables, but on Ubuntu I'm confused.
I tried running `export GOPATH=$HOME/go` in the terminal — it works, but after closing the terminal, everything resets. How do I make the setting permanent? Which file should I edit: `.bashrc`, `.profile`, `.zshrc`, or something else? I'm using the standard Ubuntu terminal (bash).
Also, it's unclear: do I need to create any folders inside `$HOME/go`? And is it mandatory to specify GOPATH?
No answers yet.
Log in to leave an answer
Blogs