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 :

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.

Leave a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: