#5 Installing Go
October 17, 2022We'll be using the Go language for the backend code. Here I'll show how to install Go on the server (Linux) and a local machine (macOS).
Linux (server)
The Go package can be downloaded from the official Go website. On the server, I can get the package with a wget
command, passing it the download link as an argument:
wget https://go.dev/dl/go1.19.2.linux-amd64.pkg
Then I can follow the steps from the Go website. The /usr
folder is protected, so we need to prefix any commands that target it with a sudo
.
The first step is to check if there's any previous Go installation.
sudo rm -rf /usr/local/go
Next, unpack the Go package with the tar
command:
sudo tar -C /usr/local -xzf go1.19.2.linux-amd64.tar.gz
Go is now installed; we just need to add it to our PATH
. PATH
is a special variable that tells the system where the executable files are located. Whenever we type the go
command, the system will know to run to the /usr/local/go/bin
file. We can update the PATH
in the ~/.profile
file:
export PATH=$PATH:/usr/local/go/bin
Now let's log out of the server and log back in for the PATH
changes to take effect. Another option is to just run the .profile
script manually. Once we're done, we can check the installation.
juraj@server:~$ go versiongo version go1.19.2 linux/amd64
We can now run Go programs on our server.
macOS (local machine)
Installing Go on our local macOS is much simpler. Just download the .pkg
file from the official Go website and install it. Then check the installation with go version
.