Golang: Download & Setup for Linux

Golang: Download & Setup for Linux

A beginner's guide on how to download and setup Golang on your Linux system

If you are used to installing stuff on Linux then you can go to this site and follow the steps there. However, if you are a beginner and you can read the steps below.

Step 1 : Remove any previous Go installation by deleting the '/usr/local/go' folder (if it exists)

$ rm -rf /usr/local/go

Step 2 : Extract the archive you just downloaded into '/usr/local', creating a fresh Go tree in '/usr/local/go':

$ tar -C /usr/local -xzf go1.19.1.linux-amd64.tar.gz

#OR you can combine above 2 commands using '&&' 

$ rm -rf /usr/local/go && tar -C /usr/local -xzf go1.19.1.linux-amd64.tar.gz

Note: Do not untar the archive into an existing '/usr/local/go' tree. This is known to produce broken Go installations.

Step 3 : Add '/usr/local/go/bin' to the PATH environment variable. You can do this by adding the following line to your $HOME/.profile or /etc/profile (for a system-wide installation):

# for $HOME/.profile and I'm using vim text editor you can use whatever you're suitable with.

$ vim $HOME/.profile
# Press i for inserting characters in file, go to the end and insert below line:
$ export PATH=$PATH:/usr/local/go/bin
# for saving and quitting press esc key then type ':wq'

# for /etc/profile
$sudo vim /etc/profile
# Press i for inserting characters in file, go to the end and insert below line:
$ export PATH=$PATH:/usr/local/go/bin
# for saving and quitting press esc key then type ':wq!'

Note: Changes made to a profile file may not apply until the next time you log into your computer. To apply the changes immediately, just run the shell commands directly or execute them from the profile using a command such as source $HOME/.profile.

$ source $HOME/.profile
OR
$ source /etc/profile

Step 4 : Verify that you've installed Go by opening a command prompt and typing the following command:

$ go version

Step 5 : Confirm that the command prints the installed version of Go.

Some VS Code setting for go

Make sure to install Go extension by "Go Team at Google".

Go to your setting, search for golang and click on settings.json. Add these lines :

"go.formatTool": "goimports",
"go.useLanguageServer": true,
"go.coverOnSingleTestFile": true,
"go.coverOnSingleTest": true,
"go.languageServerFlags": [

    ],