Home > Article > Backend Development > golang quick build
With the continuous development of the Internet, the types of programming languages are also constantly increasing and updating. Among them, golang, as an emerging programming language, has attracted more and more attention from developers because of its fast, safe, simple and easy-to-use characteristics.
In this article, I will share how to quickly build a golang development environment.
Step one: Install golang
The golang official website provides downloads of golang versions for various platforms. You can choose the corresponding version according to your computer system.
After the download is completed, just follow the download prompts to install it. After the installation is completed, open the command line window and enter the "go version" command. If the version number can be correctly output, the installation is successful.
Step 2: Install golang IDE
Although golang itself does not require the use of any specific IDE, it will be more convenient and faster to use the IDE. The following introduces several commonly used golang IDEs.
Visual Studio Code is a free, lightweight, open source cross-platform IDE developed by Microsoft that supports golang development. After installing VS Code, search for golang extensions (such as Go, Go for Visual Studio Code, etc.) in the extension market, and then install it according to the prompts.
GoLand is a professional golang IDE developed by JetBrains with very powerful functions. However, GoLand requires payment to use, but the IDEA Ultimate version also supports golang programming.
LiteIDE is a free golang development environment that can be used on Windows, Linux and Mac OS X platforms. LiteIDE provides a simple UI and rich functions, such as code completion, jump to definition, refactoring, debugging, etc.
Step 3: Set golang environment variables
Setting golang environment variables is a key step to ensure the normal operation of golang.
Windows users need to perform the following steps:
Linux and Mac users need to perform the following steps:
export GOROOT=/usr/local /go
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT/bin:$GOBIN
source ~/.bashrc
or
source ~/.bash_profile
After the setting is completed, open the command line window and enter "go". Some command instructions for golang should be output.
Step 4: Create golang project
In golang, each project needs to have a special directory structure. Create a new project directory under GOPATH using the project name as the directory name, for example:
mkdir $GOPATH/src/projectName
Create a file named main.go in the projectName directory, this It is the default compilation file of the golang compiler. Write the following code in main.go:
package main
import "fmt"
func main() {
fmt.Println("Hello, golang!")
}
This is the simplest golang program. Execute the command:
go run main.go
will output "Hello, golang!" to the command line window.
At this point, the steps to quickly build a golang development environment have ended. In the subsequent learning and development, you can use various excellent features of golang to quickly develop high-quality and efficient programs.
The above is the detailed content of golang quick build. For more information, please follow other related articles on the PHP Chinese website!