Software & AppsOperating SystemLinux

Why am I getting “command ‘go’ not found” error in Ubuntu?

Ubuntu 19

In this article, we will discuss why you might encounter the “command ‘go’ not found” error in Ubuntu and provide detailed solutions to resolve it. This error typically occurs when the Go binary is not in your system’s PATH.

Quick Answer

If you are getting the "command ‘go’ not found" error in Ubuntu, it means that the Go binary is not in your system’s PATH. To resolve this, you can either update the PATH in the .profile or .bashrc file, or install Go using the apt package manager. Restart your terminal or open a new terminal window after making any changes to the configuration files.

Understanding the PATH

The PATH is an environment variable in Unix-like operating systems, and it specifies a set of directories where executable programs are located. In simple terms, when you type a command in the terminal, the system looks for the command in the directories specified by the PATH variable.

Solution 1: Update the PATH in the .profile file

The first solution involves adding the Go binary to the PATH in the .profile file. Here is how you do it:

  1. Open the terminal and type the following command to open the .profile file:
nano ~/.profile

This command uses the nano text editor to open the .profile file located in your home directory (~).

  1. Add the following line at the end of the file:
export PATH=$PATH:/usr/local/go/bin

The export keyword is used to define environment variables. In this case, we are defining the PATH variable. PATH=$PATH:/usr/local/go/bin means that we are adding the /usr/local/go/bin directory to the existing directories in the PATH.

  1. Save the file by pressing Ctrl + X, then Y, and finally Enter.
  2. Apply the changes by running the following command:
source ~/.profile

The source command reads and executes commands from the file specified as its argument in the current shell environment.

  1. Verify that Go is installed correctly by running:
go version

Solution 2: Update the PATH in the .bashrc file

The second solution involves updating the PATH in the .bashrc file. The steps are similar to the first solution:

  1. Open the .bashrc file by running:
nano ~/.bashrc
  1. Add the following line at the end of the file:
export PATH=$PATH:/usr/local/go/bin
  1. Save the file and apply the changes by running:
source ~/.bashrc
  1. Verify that Go is installed correctly.

Solution 3: Install Go using apt

If you haven’t installed Go or if your installation is corrupted, you can install Go using the apt package manager:

  1. Update the package lists by running:
sudo apt update

The sudo command allows you to run commands with the security privileges of the superuser. apt update fetches the package lists from the repositories and updates them.

  1. Install Go by running:
sudo apt install golang

apt install golang installs the Go language.

  1. Verify that Go is installed correctly.

Conclusion

Remember to restart your terminal or open a new terminal window after making any changes to the configuration files. This ensures that the updated PATH takes effect. If none of the above solutions work, please provide more information about how you installed Go (e.g., from source or using a package manager) and any error messages you encountered during the installation process. For more information about Go, visit the official Go website.

How do I check if Go is already installed on my Ubuntu system?

To check if Go is already installed on your Ubuntu system, you can open a terminal and run the command go version. If Go is installed, it will display the installed version of Go. If Go is not installed, it will show a "command not found" error.

Can I install Go using a package manager other than apt?

Yes, you can install Go using other package managers like snap or by downloading the binary distribution from the official Go website. However, in this article, we have provided instructions specifically for installing Go using the apt package manager.

How do I uninstall Go from my Ubuntu system?

To uninstall Go from your Ubuntu system, you can run the following command in the terminal: sudo apt remove golang. This command will remove the Go package installed using the apt package manager. Additionally, you can also remove any Go-related configuration files by running sudo apt purge golang.

Leave a Comment

Your email address will not be published. Required fields are marked *