Go IDE in macOS
In this article, we are going to turn our attention to some Golang IDE’s.
Before we continue with the Go IDE’s, make sure you install Go in your machine. To install Golang in your machine go through this article. Although on the official Golang website there is a list of recommended IDE’s.
IntelliJ Goland is not free and for the beginner, you can try the 30-day trial. After trying it for 30 days, we conclude that Golang is the complete package when it comes to Go development. This entails all the features it provided and easy to install. In addition, JetBrains provides a Go plugin for IntelliJ Ultimate Edition users. For more information about this plugin see Jetbrains Go plugin.
Vim is a free and open-source IDE that supports the programming language Golang. The code editor VIM installation can be a bit confused for beginners since it requires some command through Terminal.
In this article, we are going to focus on the easy to install code editors, so everyone can get them up and running without too many difficult steps in between. From all the available Go IDE’s we are going to focus on the following code editors which can be used as a Go IDE’s which is also easy to install:
Visual Studio Code
Visual studio code is an open-source and free code editor developed by Microsoft which is redefined and optimized for building and debugging modern web and cloud applications. It also supports Git, Github and some additional features such as syntax, highlighting, intelligent code completion, snippets and code refactoring. Furthermore, it is also highly customizable which allow the user to perform the following:
- Change theme’s
- Add keyboard shortcut
- Change preferences
- Install additional extensions for additional functionalities
Golang plugin
By default, Visual Studio Code does not support Go, but there is Go plugin available in Visual Studio Code. Once the Go-plugin is installed you can start developing Go applications.
VS Code installation
This code editor can be downloaded directly from the official VS Code website.
After downloading VS studio code from the official website, just extract the .zip file where the application itself is located.
After extracting the .zip file, the VS Code application appears in the list. It is recommended to drag it to the ‘Application’ folder since if you leave the VS Code application in the Download folder it would run fine, but if you accidentally delete it, VS Code would not work anymore. Hence, drag and drop it to Application to prevent this from happening.
Just double click the VS Code in the Application folder and it will ask you for permission in order to continue. Proceed by clicking open and it will launch the VS Code app.
For a better Go programming experience in VS Code, enable the terminal. In order to do this in VS Code follow these simple steps:
Installing Go-plugin in VS Code
Installing the Go-plugin in VS Code is a straight forward process and it is these simple steps:
Create a simple hello world go application in VS Code
Creating a Go file through File -> New File and save the file with the .go extension.
Ones the file is created, just type the following Go code and save the file.
package main
import "fmt"
func main(){
fmt.Println("Hello World")
}
Running your Go code in VS Code
Now the terminal becomes handy as you can run your Go code through the VS Code embedded Terminal. Since in this example we save the Go file on Desktop, we need to navigate to Desktop in order to execute the Go file we created.
In order to navigate to Desktop just enter the following command in the VS Code terminal:
cd Desktop
Ones you navigate to Desktop, you can just execute to the following command to run your Go codes.
go run hello_world.go
Atom
Atom is an open-source text and code editor with several open-source plugins (known as ‘packages’) and it comes with a Git and GitHub already preinstalled by default. Most of the available packages are free of charge since they are developed and maintained by community developers. Atom is fully customizable through HTML, CSS, and JavaScript. This code editor has several terminal packages, but in this example, we are going to use terminal-tab, for more info about this package see: terminal-tab.
Golang support
Atom by default automatically detects Golang when it is installed on your Mac. No additional plugin installation is required.
Atom installation
Installing Atom on your mac starts by downloading the .zip file from the official website.
After downloading the zip file just double click it in order to extract it. Ones it is extracted application appears in the list (just like with VS Code).
You can open it by double-clicking the application that appears. Again just like VS Code drag and drop it to Application.
Launching the Atom application
Launching Atom is just a matter of double-clicking it in the Application folder. The verification and permission process followed. Ones these steps proceed you will see the Atom main screen.
As you can see on the main screen of the Application, Git and GitHub appear at the bottom right of the screen.
Enable Terminal in Atom
For a better programming experience, it highly recommended installing one of the available Terminal packages in Atom. So, you can run your Go code in Atom without switching to the macOS terminal each time. In this example, we are going to install the package terminal-tab developed by jsmecham. Select the Install a Package option on the application main screen and the install package window will appear.
Ones the install package window opens, select Open Installer and insert terminal-tab in the search bar on the left. If everything went well, you must be able to see the terminal-tab appear in the result section. Click install and wait until it is successfully installed.
To view the terminal in Atom just press cmd+Shift+T and it will appear in the application. For more information and documentation about the terminal-tab, see terminal-tab documentation.
Writing your first Go app using Atom
Just like the example, we did with VS Code we are going to write a simple Hello World Go application using Atom. We will start off by creating a new file by selecting File -> New File and a blank file will be created.
Next, save this blank file as a Go(.go) file File -> Save and save the file with the .go extension. In this example, we will be using the file name atom_hello_world. After conducting these steps, your Go file is created.
Run your Go application using Atom
In order to run your Go application in Atom, you must maximize the Terminal tab in order to execute the Go application. Sometimes the terminal-tab will be disabled and you need to enable it back by using the following shortcut cmd + Shift + T and it will re-appear in the application.
For this simple Go app just type the following code:
package main
import "fmt"
func main(){
fmt.Println("Hello World!")
}
In order to run this sample application, you must open the terminal tab. By default, the terminal tab initiates in the Home directory. This means that you need to navigate to the Desktop since in this example we saved the Go file on to the Desktop.
Enter the following command in the terminal-tab to Desktop:
cd Users/[username]/Desktop
To run the program just enter the following command:
go run [filename].go
In this case:
go run atom_hello_world.go
The application result will be displayed in the terminal tab as follows:
Sublime Text 3
Sublime Text 3 is a code editor with a Python application Interface (API). It supports many programming languages and markup languages, and in addition to that, functions and plugins can be added. All these plugins are community-built and maintained under free-software licenses. In Sublime Text 3 comes with a built-in Git feature which allows you to track changes without leaving the code editor.
Golang plugin
Sublime text 3 also has a Golang support package that can be installed using package control. Ones this package is installed you are all set and can start developing your own Go applications using Sublime Text 3.
Installation
Sublime Text 3 is can be downloaded directly from the official website.
After downloading the Sublime Text 3, just launch the .dmg file located in the Download folder.
Ones the .dmg file is open, drag and drop the Sublime Text application to the Application folder.
Launching the Sublime Text 3
Launching Sublime Text 3 can be launch from the Application folder.
Sublime command palette
The sublime command palette plays an important role when it comes to installing packages and other configurations. To open the command palette, just follow these simple steps:
Sublime Golang support
Before you begin writing your first Go application, there are a few handy packages that need to be installed. These packages are:
- Golang
- Terminus (for the embedded terminal in Sublime)
Installing packages in Sublime Text 3
Every package is installed through the Sublime Package control. Follow these steps to install the package control:
Installing Golang package in Sublime
The first step before writing your Go application is to install the Go package.
- Open the Sublime package control
- Enter the following: install package in the search bar and select the Package Control: Install Package
In the install package search bar for golang.
Select golang from the search result list and the package installation will start.
Installing Terminus package in Sublime
In order to get terminal in Sublime Text 3 we are going to install the terminus package. The procedure is identical to the previous steps mentioned above.
To launch terminus, open the package control and enter terminus and the list of options will appear in the list.
There are two options that you can choose to launch terminus, namely:
- Terminus: Open Default Shell in Tab (View)
- Terminus: Open Default Shell in Panel
Terminus: Open Default Shell in Tab (View)
Open the default Shell in Tab (View) will open terminus in a separated tab.
Terminus: Open Default Shell in Panel
Opens the shell at the bottom in the form of a panel which means it will stick at the bottom regardless of which tab you are currently working in.
For this example, we are going to choose the Terminus: Open Default Shell in Panel option. But at all depends on your personal choice. In this example, we are going to use this option and also modified the settings which makes it handy and easy to toggle while using Sublime Text 3.
Launch and modify terminus in Sublime text 3
Select the Terminus: Open Default Shell in Panel option and terminal will be open in a panel at the bottom of the tab.
Terminus modification in Sublime
Ones the terminal is enabled you can start executing commands. To make it a bit easier to toggle between the visibility state of terminus we are going to implement a handy command in the settings. To achieve this, we are going to implement a key bindings preference.
Perform the following steps to achieve this:
Open the package control and enter the Terminus Key Bindings and in the resulting dialog choose Preference: Terminus Key Bindings
Ones the key bindings view open, you will see two sections:
- Default settings list (Left)
- Custom Key Bindings settings list (Right)
In the custom key bindings section on the right, enter the following code to set the toggling effect.
{
"keys":["command+`"],
"command":"toggle_terminus_panel",
"args":{
"cwd": "${file_path:${folder}}"
}
}
And lastly, save this custom key bindings settings by pressing cmd + s or File -> Save.
Ones this key binding setting is successfully saved, we must be able to toggle Terminus by pressing the following keyboard shortcut: cmd + `
Writing your Go app in Sublime
Just as the previous example we are going to write a simple ‘Hello World’ Go application. In order to achieve this, we must perform the following tasks:
- Create your Go file
- Write your app code
- Save your Go code
- Run your code using terminus
Create your Go file
From the tab that is currently open, you can save the current file that is already open ending it with the .go extension. Saving the current file can be done by pressing cmd + s or File -> Save.
Write your app code
After creating the Go file, you are ready to write your Go codes in Sublime. For this Hello World Go application write the following code:
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
Save your Go code
After writing the Go code save the file by pressing cmd + S or File -> Save.
Running your Go code
Running your Go code in Sublime can be done by using Terminus. By contrast to VS code terminus start in the [user] directory. So, in order to navigate to Desktop were the Go file is saved, just enter the following command:
cd Desktop
Ones you navigate to Desktop just enter the following command:
go run sublime_hello_world.go
Conclusion
The Golang code editors described in this article are easy to install and use. Although for long term use of Sublime Text 3, it recommended purchasing a license of $80,- (One time purchase).
When it comes to pro and cons of the code editors in question, based on a Golang developer point of view, there is not a solid conclusion in this regard. Since most Golang developers use one of these code editors based on personal choice. Other reviews are based on other programming languages and not really related to Golang.
Our recommendation is to download and install these code editors and use them so you can rate them based on your own personal experience.
Relevant resources:
Follow us:
These are not IDEs, just editors. I.e. you have to run the code in the terminal and debug it with logs. No debugger there.