Install Go via APT on Debian | Generated by AI
To install Go using apt
on a Debian-based Linux system (e.g., Ubuntu), follow these steps. Note that apt
may install an older version of Go (e.g., 1.18 on Ubuntu 22.04), so you should verify if it meets your project’s requirements (check the go.mod
file in ~/Projects/clash-core
for the required Go version).
Steps to Install Go Using APT
- Update the Package Index
- Ensure your package lists are up to date:
sudo apt update
- Ensure your package lists are up to date:
- Install Go
- Install the Go package:
sudo apt install golang-go
- This installs the Go compiler, tools, and standard library.
- Install the Go package:
- Verify the Installation
- Check the installed Go version:
go version
- You should see output like:
go version go1.18.1 linux/amd64
(The version depends on your distribution’s package repository.)
- Check the installed Go version:
- Set Up GOPATH (Optional)
- Modern Go versions (1.13+) use modules, so
GOPATH
is optional, but setting it can be useful for some projects. - Edit your shell profile (e.g.,
~/.bashrc
or~/.zshrc
):nano ~/.bashrc
- Add the following:
export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin
- Save and reload the shell configuration:
source ~/.bashrc
- Modern Go versions (1.13+) use modules, so
- Retry the Build
- Navigate to your project directory:
cd ~/Projects/clash-core
- Run the
make
command again:make
- Navigate to your project directory:
Notes
- Version Check: If your project requires a newer Go version (e.g., 1.20 or later), the
apt
version might be outdated. Check the required version ingo.mod
or the project’s documentation. If needed, install a newer version manually by downloading the tarball from https://go.dev/dl/ (as described in the previous response). - Alternative Repositories: For a newer version via
apt
, you can add a third-party PPA (e.g.,ppa:longsleep/golang-backports
on Ubuntu). Run:sudo add-apt-repository ppa:longsleep/golang-backports sudo apt update sudo apt install golang-go
- Troubleshooting:
- If
go
is not found, ensure/usr/bin/go
exists (ls /usr/bin/go
). If not, reinstall withsudo apt install --reinstall golang-go
. - If you get dependency errors, run
sudo apt install -f
to fix them. - For permission issues, ensure you have
sudo
privileges.
- If
Sources
- Ubuntu Go installation guide: https://ubuntu.com/server/docs/programming-go
- General apt usage: https://help.ubuntu.com/community/AptGet/Howto
If the installed version is too old or you encounter issues, let me know your Linux distribution (e.g., Ubuntu 22.04) and the required Go version, and I’ll guide you further!