Categories
Software Development Web Development

How to install and configure Golang development environment on Ubuntu Linux

I am still working on this article as all information I’ve found about how to set PATH system wide in Ubuntu is totally wrong. I’ve yet to find a way to set Go in the PATH system wide on Ubuntu. The info in Golang Docs is even wrong for Ubuntu. This article will be updated when I discover the secret of Ubuntu PATH.

I wanted to know why Go documentation suggested saving PATH as it did, I get tired of not knowing why things are suggested. In this article I dig a little into setting PATH on Ubuntu and Linux in general.

First off go to the Golang website and download the latest version of Go. It doesn’t matter if it is in your Downloads folder, the following command unpacks it to the proper location.

Follow the instructions to unpack it for example

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

but with your version number you downloaded.

Now here is where I explain some things. The next step where it talks about setting the PATH environmental variable let me explain some things.

Where it says the following in the docs:

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):

These are the locations Linux usually will get environmental variables from.  Here is a link to explain /etc/profile I wanted to know what it did. Here is another link with more details. As you can see /etc/profile is one of he locations where linux gets things such as Environmental variables for the entire system.

The other $HOME/.profile refers to the logged in users home directroy .profile file. This is another location Linux looks for user environmental information. This article explains more about users profile files.

You can set the PATH there with this as they show :

export PATH=$PATH:/usr/local/go/bin

You put that in one of those files and what Linux does is it is adding that value to the current value for PATH you can also add it to the PATH variable for your entire system (not on ubuntu), located at /etc/environment  environment is a file. Open it with vim and you will see a really long string PATH=”longlines”

You can add to it by putting this at the end

:/usr/local/go/bin

So you will end up with something like
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin"

The way above using /etc/environment apparently isn’t system wide  on Ubuntu because of the way it disables the root account and uses something else a file called /etc/sudoers to store the PATH variable for the root user. Do not edit that directly you can destroy your login and system. User a tool called visudo.

The other ways work fine. If you add the path only to your regular user account in .profile then go won’t be available to root if you somehow need it.

/etc/profile (for a system-wide installation) is a little better because all users will have access. Otherwise each user you create you will have to add the PATH info to their .profile file, it gets to be a pain.

WARNING :
Doing it this way makes golang only available to the logged in regular user, at least on Ubuntu. /etc/environment is supposed to set PATH system wide but it doesn’t   on ubuntu.

I just wanted to dig and see why the docs suggested what it did. I get tired of everything in tech just telling people to do things without any explanation or links to info.

Next up setting configuration values, especially GOPATH – not so necessary from what I’ve been told. But the link explains the GOPATH and how to set it. I would do this because you will see many examples refer to GOPATH and you need to know what it is.

Categories
Resources Software Development

Linux how to fix Command ‘go’ not found, but can be installed with:

Command ‘go’ not found, but can be installed with:

So you just installed Go on Linux huh?

go not found
go not found error

This means you probably set the environmental variable via the command line which is temporary.  Don’t install go this way. You could do as the documentation says and add the following to a file:

export PATH=$PATH:/usr/local/go/bin

However if you look in that file it has some important looking code in it. This is because it is a script.

linux profile script
linux profile script

It felt dirty to place the above code in that file so I did some research and found a better alternative. You simply create a new file in the /etc/profile.d directory and place the above export line of code in it and save it. You can name the file anything and add .sh to it and it will be found and loaded. Then you logout and back in like the documentation suggests and open a terminal and type “go version” and it works properly.

See my go_profile.sh file :

profile.d directory
linux profile.d directory

Doing it this way instead of adding it to the ~.profile file is better because it reduces the chance of messing up the code in a file. The script actually reads all of the files in the profile.d folder and this is why it works. For more information see this article in the section “Persistent environment variables”. You can do any other environmental variables you need set this way too.

Another reason for this error is you need to logout of your Linux computer then log back in or restart/reboot the system. The variables are read and set at login time or reboot/restart.

Categories
Resources Web Development

Golang web development resources and links

Articles

Session based authentication in Go

Categories
Resources Software Development Web Development

Golang useful resources.

Useful Golang programming resources

Making The Move From Scala To Go, And Why We’re Not Going Back -> a great article about some reasons why a company switched to golang. It mentions some important things to consider. Golang is great for microservices.

Golang book. Free online book.

50 Shades of Go: Traps, Gotchas, and Common Mistakes for New Golang Devs

Golang Modules explained

More about Golang Modules

Golang Slices explained

Golang pointers explained in the tour

Golang interfaces explained. This is a very helpful article. I found the interfaces section on tour of go to be nonsensical jibberish. Here is the pure jibberish

var a Abser
f := MyFloat(-math.Sqrt2)
v := Vertex{3, 4}

a = f // a MyFloat implements Abser
a = &v // a *Vertex implements Abser

How is this implementing anything? It looks to me like assignment? Makes ZERO sense. Most of the tour is awesome and makes sense but this entire section is pure fail. It causes more questions than answers. Like this
// In the following line, v is a Vertex (not *Vertex)
// and does NOT implement Abser.
a = v

Ok  I am new. This to me looks like reassignment. Once again how does assignment make something implement something? And why not explain it to the new users? Any details as to what is going on would be helpful to new comers. If you quote it out and run the program it works. This section needs heavy updating and explaining. This is purely WTFF??? This is literally the absolute worst part of the entire Tour. This is where I hit my WTF moments and had to start using google to DECIPHER the encoded message.

Thinking in Go. This article is a must read for anyone coming from an OOP background such as Java wanting to understand Golang. There are no classes. No inheritance. No generics. No this. No that and No. Golang requires thinking entirely differently. Interfaces are the hardest thing to wrap my mind around so far.  The implicit magic is something  I don’t like I prefer words like implements to make my code more clear. If I could just find good enough information I’d understand it. I literally have to undo all of the years of OOP damage. When I first encountered Golang I heard that interfaces confused most new people, I understand why now. It is not just interfaces it is learning to think and build software in an entirely new alien way.

Golang Structs explained

More on Golang Interfaces — because they are nothing like interfaces you have face in other languages. The whole implementing thing is just totally wild. I hate implicit bullshit. It’s just unneeded magic for no reason other than to drop a few characters.https://www.digitalocean.com/community/tutorials/how-to-deploy-a-go-web-application-using-nginx-on-ubuntu-18-04

Thinking about Interfaces in Go — another great article about Golang interfaces. Interfaces are the most complex thing in go, so multiple references helps  more.

Go for Java Programmers — this is an awesome series of articles for java programmers coming to Golang. This is also helpful to PHP programmers since PHP is so similar to Java these days.

Go in VSCode: Must-have extensions and some limitations

Building Web Applications with GO — a free online book about how to build a web app with golang

How to deploy a Golang Application on Linux with NGINX 

 Go: the Good, the Bad and the Ugly   An article with lots of good information about Gotchas in Golang and some best practices.
Golang: Concurrency is Hard; So What Can We Do About It? A very good article about concurrency in Golang

Everything you need to know about Packages in Go – a great article all about packages.

Publishing Golang packages – golang article about how to version packages/modules

Why you should use a Go module proxy– why and how to create a go module proxy

Go 1.13 for Private Repositories  – What are private repositories

Videos

GothamGo 2018 – Things in Go I Never Use by Mat Ryer

7 common mistakes in Go and when to avoid them by Steve Francia (Docker)