❝Friends who are preparing to learn go will install and use it directly on Windows at the beginning. Today I will write an installation tutorial on Linux for you.
❞
This article uses tools
centos7.3 Virtual machine
1. Install GO
Open the official website of gohttps://golang.org/dl/
, and directly install the one selected in the click box. Right-click the mouse and there will be an address. Save this address and use the wget command below. Just download itExecute the command
wget https://golang.org/dl/go1.14.4.linux-amd64.tar.gz
, download itExtract go to
Under /usr/local
Execution instructionstar -xzf go1.14.4.linux-amd64.tar.gz -C /usr/local/
After decompression is completed, it will be directly under /usr/local go folder
Up to this step, our go has been installed. Next, we need to configure environment variables.
2. Configure environment variables
GOROOT: This is the installation location of go, in this article it is /usr/ local/go GOPATH: This is the directory of the project
The configuration on Windows is like thisNext we need to configure the environment variables of go on Linux, in the file
/etc/profile
Add the following code
<span style="display: block; background: url(https://imgkr.cn-bj.ufileos.com/97e4eed2-a992-4976-acf0-ccb6fb34d308.png); height: 30px; width: 100%; background-size: 40px; background-repeat: no-repeat; background-color: #282c34; margin-bottom: -7px; border-radius: 5px; background-position: 10px 10px;"></span><code class="hljs" style="overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; letter-spacing: 0px; padding-top: 15px; background: #282c34; border-radius: 5px;">export GOROOT=/usr/local/go<br/>export GOPATH=/goLearn<br/>export PATH=$PATH:$GOROOT/bin<br/></code>
and execute source ./profile
Execute go version to check whether go is installed successfully. If the installation is successful, the following figure will appear. (If it is inconsistent with the version downloaded by Kaka, it is the version number you downloaded yourself)
3. Execute the first GO program on Linux
This directory must be consistent with the set GOPATH, which is the goLearn directory
Create src in this directory of golearn, and then store your project in this directory That’s it
This case is just a simple implementation process. In order to only demonstrate the execution problem of the GO program, Kaka will always output some articles about go later and then execute this program to check whether it can be executed successfully. There are many ways to execute go programs. Here we just use the go run command for demonstration.
This is just a simple implementation process. The main purpose of this article is to install GO on Linux.
If you happen to want to know about go, then you can continue to check Kaka’s articles in the GO column of this site.
The above is the detailed content of How to run your first go program on Linux. For more information, please follow other related articles on the PHP Chinese website!

Gooffersrobustfeaturesforsecurecoding,butdevelopersmustimplementsecuritybestpracticeseffectively.1)UseGo'scryptopackageforsecuredatahandling.2)Manageconcurrencywithsynchronizationprimitivestopreventraceconditions.3)SanitizeexternalinputstoavoidSQLinj

Go's error interface is defined as typeerrorinterface{Error()string}, allowing any type that implements the Error() method to be considered an error. The steps for use are as follows: 1. Basically check and log errors, such as iferr!=nil{log.Printf("Anerroroccurred:%v",err)return}. 2. Create a custom error type to provide more information, such as typeMyErrorstruct{MsgstringDetailstring}. 3. Use error wrappers (since Go1.13) to add context without losing the original error message,

ToeffectivelyhandleerrorsinconcurrentGoprograms,usechannelstocommunicateerrors,implementerrorwatchers,considertimeouts,usebufferedchannels,andprovideclearerrormessages.1)Usechannelstopasserrorsfromgoroutinestothemainfunction.2)Implementanerrorwatcher

In Go language, the implementation of the interface is performed implicitly. 1) Implicit implementation: As long as the type contains all methods defined by the interface, the interface will be automatically satisfied. 2) Empty interface: All types of interface{} types are implemented, and moderate use can avoid type safety problems. 3) Interface isolation: Design a small but focused interface to improve the maintainability and reusability of the code. 4) Test: The interface helps to unit test by mocking dependencies. 5) Error handling: The error can be handled uniformly through the interface.

Go'sinterfacesareimplicitlyimplemented,unlikeJavaandC#whichrequireexplicitimplementation.1)InGo,anytypewiththerequiredmethodsautomaticallyimplementsaninterface,promotingsimplicityandflexibility.2)JavaandC#demandexplicitinterfacedeclarations,offeringc

Toensureinitfunctionsareeffectiveandmaintainable:1)Minimizesideeffectsbyreturningvaluesinsteadofmodifyingglobalstate,2)Ensureidempotencytohandlemultiplecallssafely,and3)Breakdowncomplexinitializationintosmaller,focusedfunctionstoenhancemodularityandm

Goisidealforbeginnersandsuitableforcloudandnetworkservicesduetoitssimplicity,efficiency,andconcurrencyfeatures.1)InstallGofromtheofficialwebsiteandverifywith'goversion'.2)Createandrunyourfirstprogramwith'gorunhello.go'.3)Exploreconcurrencyusinggorout

Developers should follow the following best practices: 1. Carefully manage goroutines to prevent resource leakage; 2. Use channels for synchronization, but avoid overuse; 3. Explicitly handle errors in concurrent programs; 4. Understand GOMAXPROCS to optimize performance. These practices are crucial for efficient and robust software development because they ensure effective management of resources, proper synchronization implementation, proper error handling, and performance optimization, thereby improving software efficiency and maintainability.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use
