command 'go' not found
This is not a programming question.
I have a machine running Ubuntu, and I installed Golang on it. It was working fine... I even ran a few programs, but the "go1.11.2.linux-amd64.tar.gz" file was in my home directory so I thought it would be okay to move it to the Downloads directory. After moving it, I can't use any Go command, and I get command 'go' not found. I tried moving the file back to the home directory, but I'm still getting the same error.
Can anybody explain to me what's going on? Thanks!!
richie@richie-ThinkPad-T430:~$ go version
Command 'go' not found, but can be installed with:
sudo snap install go # version 1.11.2, or
sudo apt install golang-go
sudo apt install gccgo-go
See 'snap info go' for additional versions.The commands I used to install Go :
wget
sudo tar -C /usr/local -xzf go1.11.2.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
source ~/.profile 10 6 Answers
Jos in the comments above is likely correct. You need to add the change to PATH in your .profile. From the install doc (emphasis added):
Add
/usr/local/go/binto the PATH environment variable. You can do this by adding this line to your/etc/profile(for a system-wide installation) or$HOME/.profile:export PATH=$PATH:/usr/local/go/bin
From: Installed golang still go: command not found #20
Use this command:
sudo apt update && sudo apt install golang 5 Use nano ~/.profile to edit the file and add the following:
export PATH=$PATH:/usr/local/go/binSave the file using the command source ~/.profile.
Check the version:go version
Make sure that the GOPATH environment variable is set to /usr/local/bin.
Try adding the exact export command to the ~/.bashrc file.
You need to source the ~/.bashrc file for changes to take place in your current terminal. From next time onward whenever you open a terminal, you should be able to find the go command. This worked for me.
One line command to install go,
[ ! -d "/usr/local/go" ] && cd /tmp && wget && tar -C /usr/local/ -xzf go1.17.4.linux-amd64.tar.gz && cd /usr/local/ && echo "export PATH=\$PATH:/usr/local/go/bin:\$HOME/go/bin" >> ~/.bashrc && echo "export GOROOT=/usr/local/go" >> ~/.bashrc && echo "export PATH=\$PATH:/usr/local/go/bin:\$HOME/go/bin" >> /home/*/.bashrc && echo "export GOROOT=/usr/local/go" >> /home/*/.bashrc && source ~/.bashrc && source /home/*/.bashrcNote: Run rm /usr/local/go before running this code if it is not working. It will install it for the user you are logged in.
Command explanation (for those who wants to know, so you can edit it if you want):
[ ! -d "/usr/local/go" ]to check if go already downloaded. If it is already there the command will not work. You need to runrm /usr/local/goto make it working.cd /tmp && wgetto move to tmp directory and download go binary.tar -C /usr/local/ -xzf go1.17.4.linux-amd64.tar.gzto unzip the downloaded tar file to installation directory/usr/localcd /usr/local/ && echo "export PATH=\$PATH:/usr/local/go/bin:\$HOME/go/bin" >> ~/.bashrc && echo "export GOROOT=/usr/local/go" >> ~/.bashrc && echo "export PATH=\$PATH:/usr/local/go/bin:\$HOME/go/bin" >> /home/*/.bashrc && echo "export GOROOT=/usr/local/go" >> /home/*/.bashrc && source ~/.bashrc && source /home/*/.bashrcto setGOPATHandGOROOTfor bash terminal.