Use IntelliJ idea to build a Golang development environment under WINDWOS (Take a poop pee super detailed)

Source: Internet
Author: User
Tags install go sublime text
This is a creation in Article, where the information may have evolved or changed.

Before using Golang in the time are under Mac OS X and Linux, with GVM installed Golang, automatically set up the relevant environment, install a sublime text installation Gosublime plug-in. The construction process is fairly straightforward.

Now that you're still under Windows, it's a lot more painful to find that you continue to configure your development environment with sublime text. This turned to IntelliJ idea. Don't say much nonsense. The following is the installation of the whole environment. In fact, a lot of online building tutorial is too old, it is no longer applicable.

I. First install the Golang

You can download the source code to compile, or you can download the binary package directly. I am here to download the latest go1.2 R5 64-bit version (32-bit system students should know that they should download 32-bit) address in this Go1.2rc5.windows-amd64.msi

Installation process is relatively simple, directly ferocious press the next step.



Here can be modified to the required installation path, but this path to remember, my own do not modify the



after the installation is complete, it is a good idea to log off for the environment variable to take effect .

The Setup program can be found in the environment variables to help us modify the two environment variables

1. Added an environment variable named Goroot


2. Added path to Go/bin at the end of path


This modification ensures that the Golang can be invoked normally from the command line. We can also enter the go env under the command line to see which environment variables are set


To see the above output, the Golang has been installed correctly. If you don't see it, don't go down there.


Two. Installing IntelliJ idea

For IntelliJ idea claims to be the best * * * (people dare to write on the homepage of the good Java and Polyglot IDE), perfect hints, support refactoring, I just want to say, who use who cool. Anyway, I've jumped from sublime text.

Download the IntelliJ Idea 13 Open source version (133.124) here, or download it yourself to the homepage.

Just go crazy and do the next step.


Three. Download the plugin for compiling Golang

Go to plugin author github to download:

Https://github.com/mtoader/google-go-lang-idea-plugin


Unzip after download. Open the project with IntelliJ idea



After you open the project, you need to do a little bit of configuration, mainly configuring three things, one is the JDK, and the IDE plugin is related.

Click this button in the upper right corner, or use the Ctrl+shift+alt+s shortcut key.


Add JDK to the left SDKs, as well as IDE plugin related things



It looks like this when the path is set up well.


Configure this to start compiling our plugins. Back to the IDE's main interface, click Build, Prepare all Plugin Modules for Deployment


Here to pay attention to ha, do not point to run but to build, I compile before the time I dropped the hole inside ....

This is going to pop up a little window directly dot OK


Then you start compiling, and then you compile it in a minute.



Four. Installing plugins

From File->settings or ctrl+alt+s, bring up the settings panel, locate the plugins project, and click Install plugin from disk.


Then select the plugin you compiled just now.


Five. New Golang test Project

After installing the plugin, you can see that the Golang related project option is already available on the left in new project, but the SDK for Golang has not been specified at this time. To set up a bit


Remember the first step to install go in the C:/go directory, now come in handy, specify its path. After setting the path, it will look like this



After we created the project, we had to run the simplest Hello program in a little pity Dorado place.

The first one is to modify the package name to main, and the final code looks like this

Package Main

Import "FMT"

Func Main () {
Fmt. Printf ("Hello slug!")
}

This time, if we run directly, we'll click Main.go.


This time an error message appears

Error running Main.go:Cannot find target. is main function defined in main package?

I do not know how to solve this error, I use other methods to compile, if anyone knows also please tell me.

My approach is to create a external tools myself, file->settings or ctrl+alt+s bring up the settings panel and find the external tools option. Click on the right green Plus to create a new one.


Create a external tools such as:


After adding, you need to configure the project to replace the original compilation with this external tools.


Remove the original make and add the external Tools we just added.


.

OK Now you can run the program directly.



Reference:

Golang IntelliJ Idea Plugin Google-go-lang-idea-plugin compilation method build in Windows

At first, I compiled the plug-in is not correct, the installation of the plug-in is always wrong, see this post has introduced the method after the contact with the man, the man is very enthusiastic next day cut the figure of step to teach me how to compile. Thanks for the dude.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.