GO - INSTALLATION
To run Go Programs in you PC, you need to install Go first.
Installation of Go for Windows OS
Below are the steps to install Go on Windows OS :
×
-
Goto the below link and download the latest version of Go.
https://golang.org/doc/install
Select the 'Windows' tab as shown in the below image
-
Once the 'go1.15.6.windows-amd64.msi' file is downloaded. Double click to open it.
-
After that the setup window will open. Now, you can start the Installation.
-
Once Go is Installed, you can open the Command Prompt and Type 'go version'.
If the version is shown then Go is successfully installed in your system.
Installation of Go for MAC OS
Below are the steps to install Go on MAC OS :
-
Goto the below link and download the latest version of Go.
https://golang.org/doc/install
-
Once the 'go1.15.6.darwin-amd64.pkg' file is downloaded. Double click to open it.
-
Then follow the below steps to Install Go.
-
Once Go is Installed, you can open the Command Prompt and Type 'go version'.
If the version is shown then Go is successfully installed in your system.
Now, that we have Installed Go. Let us see how we can run a Go Program.
Running a Go Program in Windows OS
Let us write a Program that will print 'Hello World'.
-
The first thing we will do is open 'Notepad' in Windows OS.
-
Once 'Notepad' is opened. You can type the lines of code there.
And now, since we are trying to print 'Hello World'. Type the below lines.
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
-
Then save with '.go' extension. Say 'FirstProgram.go'.
-
Then run using the command 'go run FirstProgram.go'.
Running a Go Program in MAC OS
Let us write a Program that will print 'Hello World'.
-
The first thing we will do is open 'TextEdit' in MAC.
-
Once 'TextEdit' is opened. You can type the lines of code there.
And now, since we are trying to print 'Hello World'. Type the below lines.
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
-
Then save with '.go' extension. Say 'FirstProgram.go'.
-
Then run using the command 'go run FirstProgram.go'.