How to install Go

I have spent the past 3 hours very confused.

Im trying to install golang and the guide tells me to "Remove any previous Go installation by deleting the /usr/local/go folder (if it exists), then extract the archive you just downloaded into /usr/local, creating a fresh Go tree in /usr/local/go:
$ rm -rf /usr/local/go && tar -C /usr/local -xzf go1.23.2.linux-amd64.tar.gz
(You may need to run the command as root or through sudo). "

However when trying to do this it says the directory cant be found. I tried to manually create it but it says i dont have permission. thanks.

Maybe you’ve removed /usr/local directory?
What’s the output of this command?

ls -l /usr /usr/local

/usr:
total 104
drwxr-xr-x. 2 root root 36864 Nov 3 09:22 bin
drwxr-xr-x. 2 root root 4096 Jan 28 2024 games
drwxr-xr-x. 6 root root 4096 Jun 24 23:10 include
drwxr-xr-x. 92 root root 4096 Sep 21 05:02 lib
drwxr-xr-x. 2 root root 4096 Sep 21 05:01 lib64
drwxr-xr-x. 12 root root 4096 Sep 21 05:02 libexec
drwxr-xr-x. 10 root root 4096 Jun 24 22:29 local
drwxr-xr-x. 10 root root 4096 Jun 24 22:29 local.orig
drwxr-xr-x. 2 root root 20480 Sep 30 08:58 sbin
drwxr-xr-x. 220 root root 12288 Nov 3 09:21 share
drwxr-xr-x. 2 root root 4096 Jan 28 2024 src

/usr/local:
total 32
drwxr-xr-x. 2 root root 4096 Jun 24 22:29 bin
drwxr-xr-x. 2 root root 4096 Jun 24 22:29 etc
drwxr-xr-x. 2 root root 4096 Jun 24 22:29 games
drwxr-xr-x. 2 root root 4096 Jun 24 22:29 include
drwxr-xr-x. 3 root root 4096 Jun 24 22:31 lib
lrwxrwxrwx. 1 root root 9 Jun 24 22:29 man → share/man
drwxr-xr-x. 2 root root 4096 Jun 24 22:29 sbin
drwxr-xr-x. 7 root root 4096 Jun 24 22:40 share
drwxr-xr-x. 2 root root 4096 Jun 24 22:29 src
user@vm:~$

It looks fine and should work.
Copy and paste here the terminal content (both the command and their output) when you run the commands e.g.:

[user@vm:~$]$ rm -rf /usr/local/go && tar -C /usr/local -xzf go1.23.2.linux-amd64.tar.gz
[user@vm:~$]$ 

Once you sorted this out, make sure that you are running the command in a template or a standalone qube, otherwise the changes won’t persist after a reboot.

edit: I was wrong, AppVM do not inherit /usr/local from a template…

This won’t work for a template since this command is extracting the Go files in /usr/local so this needs to be done in an app qube or in a standalone qube.

2 Likes

$ rm -rf /usr/local/go && tar -C /usr/local -xzf go1.23.2.linux-amd64.tar.gz
tar (child): go1.23.2.linux-amd64.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

I dont see /usr/local/go at all. But i still cant add go1.23.2.linux-amd64.tar.gz to it.

I also tried to use xarchiver to unzip it in /usr/local but that also did not work.

the error says the file go1.23.2.linux-amd64.tar.gz does not exist, so it’s normal you can’t extract it.

You need to run the command in the same directory where you downloaded go1.23.2.linux-amd64.tar.gz

Im assuming you mean run the command in /home/user/Downloads, if so i did that and it says “tar: go: Cannot mkdir: Permission denied
tar: go/test/winbatch.go: Cannot open: No such file or directory
tar: go: Cannot mkdir: Permission denied
tar: go/test/writebarrier.go: Cannot open: No such file or directory
tar: go: Cannot mkdir: Permission denied
tar: go/test/zerodivide.go: Cannot open: No such file or directory
tar: go: Cannot mkdir: Permission denied
tar: go/test/zerosize.go: Cannot open: No such file or directory
tar: Exiting with failure status due to previous errors”

There was many more lines but i just shortened it.

Run this command from the /home/user/Downloads directory:

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

It does if you create the AppVM after the template…and in fact what really happens is whatever is in /usr/local.orig/bin on the template gets copied to /usr/local/bin when the appvm is created (this applies whether or not you’re using the AppVM directly or as a template for disposbles).

This is not very good news if you’re dealing with an AppVM you don’t want to recreate (because it has data on it)–you’ll have to go in and manually adjust /usr/local/bin to have whatever is in /usr/local.orig/bin, but I believe most times a dvm template doesn’t have data on it and can be deleted and recreated without loss.

1 Like

I did it, nothing happened for a few seconds. then i think it finished. no text was outputed.

That means that the command was executed successfully and the Go files are now installed in the /usr/local directory.

1 Like

You are the King of Qubes. Thank you.

Do you mind telling me how you solved the issue? Im assuming you added sudo giving you permission to access /usr/local/go ?

User don’t have permission to write in /usr/local directory:

user@vm:~$ ls -la /usr/local
total 40
drwxr-xr-x 10 root root 4096 Oct 23  2023 .

You need to be root to change the files there so you need to execute the commands as root with sudo for this.

1 Like

hi, so of course i have a new issue lol

everytime i try to type go version it says command not found, unless i do “export PATH=$PATH:/usr/local/go/bin” it will then output the version. but whenever i close the terminal go no longer works and i have to do the path again. why is this? i believe it is causing me errors when i try to “build” something from github. it outputs “1: @echo: not found
Building…
file_name: 4: cls: not found”. that is after i do the path thing.

Add it to the $HOME/.profile file to make it persistent as stated in the guide:

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

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

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.

No idea if it’s related.