This is a step-by-step guide to install Go in Linux user space and setting up Emacs development environment. It shows a user-scoped manual installation without relying on external tools. If you manage Go using dedicated tools or distribution-specific packages, skip the next section and go to the Emacs configuration one.
Go installation
Download latest Go version from its website and extract the zip file contents.
Now you have a folder (e.g. go1.24.4.linux-amd64) containing another folder named go with a structure like this.
$ tree -L 2
.
└── go
├── api
├── bin
├── codereview.cfg
├── CONTRIBUTING.md
├── doc
├── go.env
├── lib
├── LICENSE
├── misc
├── PATENTS
├── pkg
├── README.md
├── SECURITY.md
├── src
├── test
└── VERSION
10 directories, 8 files
Put the directory in a user-accessible location, e.g. ~/LocalApps/go1.24.4.linux-amd64.
Then, link all the go binaries so they can be found by the OS.
$ ln -s ~/LocalApps/go1.24.4.linux-amd64/go/bin/* ~/.local/bin/
If your distribution, like any modern Linux distribution, is XDG Base Directory Specification compliant, ~/.local/bin/ is already in your $PATH environment variable.
Gopls
In order to have in-editor code suggestions, formatting, etc, you have to install the Go LSP server named Gopls.
Gopls is the official language server protocol (lsp) implementation provided by the Go team. It is intended to replace the existing third party tools for code formatting (gofmt), automatic imports (goimports), code navigation (godef/guru), type and function descriptions (godoc/godef), error checking, auto completion (gocode), variable and type renaming (rename), and more. Once gopls is stable the older tools will no longer be supported.
Install it with one command.
$ go install golang.org/x/tools/gopls@latest
In order to know where Go is installing packages, use go env and look for GOPATH.
$ go env | grep GOPATH
GOPATH='/home/alessandro/go'
This folder contains all the Go related packages installed with go install.
Moreover, it contains a sub-directory named bin with runnable binaries installed by some of such packages (gopls is one of them).
$ tree -L 2
.
├── bin
│ └── gopls
└── pkg
├── mod
└── sumdb
Using the same technique shown above, add gopls to the $PATH.
$ ln -s ~/go/bin/gopls ~/.local/bin/gopls
Go mode
Installing go-mode for Emacs requires only three lines of code in your init.el file.
(use-package go-mode
:ensure t
:defer t)
Eglot LSP client for gopls
Nowadays Eglot LSP client is already bundled in the standard Emacs distribution, so there is nothing to do left.
Just run M-x eglot in your Go buffer and it will start the gopls server providing suggestions, documentation, …
It will communicate you its status with a message.
[eglot] Connected! Server `gopls' now managing `(go-mode go-dot-mod-mode go-dot-work-mode go-ts-mode go-mod-ts-mode)' buffers in project `gkg'.
If you want it to automatically start while editing Go files add it to the go-mode-hook in your init.el file.
(add-hook 'go-mode-hook 'eglot-ensure)
Gopls integration with other packages
When using Eglot with gopls you have support for:
- xref cross references
- ElDoc inline documentation
- Flymake on-the-fly checks
- Company code completion
- project integration
For more information about gopls configuration, including LSP-mode support, see the project page.