Sublime is a lightweight text editor with a powerful plug-in system that can meet the development needs of various programming languages.
Golang is an emerging high-performance programming language that has become one of the mainstream languages in the fields of cloud computing and big data.
In this article, we will introduce how to install Golang in Sublime to facilitate your development practice.
1. Install Sublime
First, download the installation package suitable for your operating system version from the Sublime official website, and then install it according to the prompts.
2. Install the Go language package
There are two steps to install the Go language package:
1. Download the Go language development package
on the Golang official website , download the development package suitable for your operating system version. After the download is completed, you can install it according to the installation method of the operating system.
2. Set environment variables
Setting environment variables allows the computer to find the installation directory of the Go language and then use the Go language.
In Windows systems, you can follow the steps below:
(1) Click "System and Security" in the Control Panel, and then click "System".
(2) Click "Advanced System Settings" and then click "Environment Variables".
(3) In "System Variables" (or "User Variables"), find the "Path" variable and click "Edit".
(4) In the pop-up "Edit Environment Variables" window, add the Go language installation directory to the variable value list.
(5) After the setting is completed, you need to reopen the Sublime software to take effect.
In Mac system, you can follow the following steps:
(1) Open Terminal.
(2) Enter the following command:
echo 'export GOROOT=/usr/local/go' >> ~/.bash_profile echo 'export GOPATH=$HOME/Go' >> ~/.bash_profile echo 'export PATH=$PATH:$GOROOT/bin' >> ~/.bash_profile
Among them, /usr/local/go
represents the installation directory of the Go language.
(3) Enter the following command to make the settings take effect:
source ~/.bash_profile
(4) After the settings are completed, reopen the Sublime software to take effect.
3. Install the Sublime plug-in
In Sublime, you can use plug-ins such as GoSublime and Go compiler to support the development of Golang. Here we take GoSublime as an example.
1. Install Package Control
Package Control is Sublime’s own plug-in management tool, which can easily install, uninstall and manage plug-ins.
In Sublime, press "ctrl " (or "cmd
"), open the console, then paste the following code and press Enter:
import urllib.request,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404' + 'e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)
2. Installation GoSublime
In Sublime, press "ctrl shift p" (or "cmd shift p"), open the command panel, enter "install package" and press Enter, then enter "GoSublime" and press Enter.
After the installation is complete, you can use the Go language for development in Sublime.
4. Writing a Hello World program
In the previous steps, we have completed the installation and configuration of Sublime and Golang. Now let us write a simple Hello World program.
1. Create a new file
In Sublime, press "ctrl n" (or "cmd n") to create a new file.
2. Enter the program code
Enter the following code:
package main import "fmt" func main() { fmt.Println("Hello, world!") }
Code description:
This program uses the fmt package (that is, the formatting of the standard library Input and output library), and use the Println method to output a line of text "Hello, world!" to the console.
3. Save the file
In Sublime, press "ctrl s" (or "cmd s") to save the file and save the file to the working directory you set. .
4. Run the program
Open the command line terminal, switch to the directory where the program is located, and then enter the following command:
go run hello.go
The program will output "Hello, world" on the console !"Information.
At this point, we have successfully installed, configured and used Golang and Sublime. I hope this article is helpful to you. For more tutorials about Sublime and Golang, please stay tuned for subsequent articles.
The above is the detailed content of How to install golang in sublime. For more information, please follow other related articles on the PHP Chinese website!