# Where to Install Go on Linux

🗓 July 28, 2018 | 👱 By: Hugh

The official instructions for installing Go are fairly easy to work through. If you're new to Linux though it can be a bit daunting installing something from a tar file rather than apt-get install or an exe or msi on Windows. This post is less about installing Go end to end, and more about running through some of the questions I had when i was getting used to Linux and installing Go, particularly about where to put things.

Should I install it in /usr/local/ or to a custom location?

In the vast majority of cases, install it in /usr/local/go/ as per the instructions. There might be cases where you need to put it somewhere else, such as a shared system, or maybe some bizarre company policy, but in general it is best to put it where the instructions say. The benefits are:

  • If anyone else is using the system they'll know intuitively how it is set up.
  • You don't need to modify other environment variables to point to the right location (e.g. GOPATH).
But why /usr/local/go/ rather than /opt/go/?

There is no defined spot to put installed software in Linux, for a period /opt/ was the place to put it, now I guess /usr/local/ is. It seems to vary over time with no real good reason that i am aware of other than the popular convention of the day.

Should I update the PATH variable in /etc/profile or $HOME/.profile?

In case it needs clarification, the PATH environment variable lists directories to look in when you type a command into the shell. If you don't update PATH to include Go's bin directory, then when you write go run code.go, you'll get a command not found error since it doesn't know where to find the go binary.

The difference between updating it in /etc/profile vs $HOME/.profile is that the first will update every user of your systems PATH, whereas the second will only update yours.

If you do a global installation (put it in /usr/local/ rather than your home directory) then it makes sense to update PATH in /etc/profile so that it will be easily available to all users. Either way they'll be able to access it, it just saves them adding it to the path themselves.

Alright, it's installed. Now what?

If you haven't run through the Tour of Go, then I'd suggest starting there to get a great intro to what Go is all about.

If you have done the tour, then check out the How to Write Go Code page to get a really comprehensive overview of Go conventions.

If you just want to mess around and play with the language, then read this future post (that doesn't exist yet, so there is no link...).