The biggest obstacle in learning a new programming language is to build a development environment. Golang is famous for its simple and beginner-friendly syntax, but it does not imply that you are free from the obstacle.
And debugger is always one of the best partners in development and you must need it soon. IntellJ, which has a pretty reputation in Java, Kotlin and other languages has been one best option for a while as an IDE for golang. But a recent update in IntellJ discontinues the compatibility with Go plugin and the support for Go development is now only provided with a non-free plugin Gogland. Considering its functions, it is actually worthy, but it must be too much if you only want to try golang first.
So I would introduce how to build golang development environment with golang itself, its debugger and a GUI interface with Atom editor, only with free options. Here is all you will install in this article:
For easy installation, we will use package managers. Make sure that you can use homebrew (for Mac) or apt-get for Linux and apm for Atom package installation.
It is very easy to install golang itself with homebrew. The familiar command
brew install go
should work and you can confirm it with
go version
The debugger delve is also available with homebrew, but it is not as simple as downloading golang. Anyway try
brew install go-delve/delve/delve
On Mac, this command might be blocked right after caching zipped delve due to a security issue. In such a case, you can use a shell script to generate a certification. You first expand the delve with
cd ~/Library/Caches/Homebrew
unzip delve-1.0.0-rc.2.tar.gz
if the downloaded version is delve-1.0.0-rc.2.tar.gz. If you are not really sure about the name of the downloaded file, you can get it like ls | grep delve
or something.
You will find a shell script file to solve the security issue by generating a proper certification.
sh ~/Library/Caches/Homebrew/delve-1.0.0-rc.2/scripts/gencert.sh
Then you can execute again
brew install go-delve/delve/delve
and it must work.
Note that those commands above are only valid when you have not changed the caching directory for homebrew. If you have changed it from the default setting, the parameters for the directory must be modified as you set.
The installation can be confirmed with
dlv version
If you have successfully installed it, the output of this command will be like
Delve Debugger
Version: 1.0.0-rc.2
Build: v1.0.0-rc.2
To enjoy golang and delve on Atom editor, you can install go-debug manually on Atom or with a command
apm install go-debug
The first time you open Atom after this installation, Atom will ask whether it should install dependencies as well or not. Answering 'yes', Atom will automatically install dependencies. These efforts to install Atom-related plugins and dependencies have no difference from efforts on Linux.
sudo add-apt-repository ppa:gophers/archive
sudo apt update
sudo apt-get install golang-1.9-go
If you only use a familiar command like sudo apt-get install golang
, it will install an old version of golang (1.5.x). There are not big differences in its syntax and you will not suffer very much from the version difference, while you code without the debugger. However the go debugger delve is incompatible with the old version.
If you are not sure which version of golang you have installed, you can confirm with
go version
Once you confirmed the installation, you can employ go get
to install delve. While on Mac you are supposed to solve some blocks due to security issues, on Linux it is pretty easy to install delve. Just type or copy
go get github.com/derekparker/delve/cmd/dlv
and execute it. Done.
Also, you can confirm its installation with:
dlv version
To enjoy golang and delve on Atom editor, you can install go-debug manually on Atom or with a command
apm install go-debug
The first time you open Atom after this installation, Atom will ask whether it should install dependencies as well or not. Answering 'yes', Atom will automatically install dependencies. These efforts to install Atom-related plugins and dependencies have no difference from efforts on Mac.