How to Build, install and run Go Programs in Windows – GoLang 1.20



How to Build, install and run Go Programs in Windows – GoLang 1.20

How to Build, install and run Go Programs in Windows - GoLang 1.20

In this video we are going to show how to build, install and run golang programs in Windows Environment.

Below are steps involved.

I will be creating one new directory called “GoExamples2” where I am going to place .go files.

Now I am copying one go program which has main() function i.e. i am going to copy one standalone go program.
This program contains the logic to connect to oracle database 12c and fetch the records of person table.

Next open the command prompt and go to D:GoExamples2 directory and initialize or create the go.mod file using (go mod init).
creating the go.mod file is mandatory if you want to build and install your application.

Now I am going to download and install the third party modules using “go get” command.
These modules entries are added to go.mod file and it will be used by the go program which i have shown.
we can see the downloaded modules here C:UsersRAMANATHANgo

Now I am going to execute the “go build” command which will compile packages and dependencies.
Which means it will create one .exe file (in windows) same as module name.
Here the module name is oracle12c (you can see the module name in go.mod file). so .exe file will be created as oracle12c.exe.
Now we can see I can able to run the exe simply typing the name oracle12c.exe.

Now I am going to customize the .exe file name i.e. give my own name for .exe instead of module name using the command “go build -o”.

Now I am going to show you some basic environment variables GOPATH and GOROOT
GOPATH is —- C:UsersUSERNAMEgo here it is C:UsersRAMANATHANgo which contains all the downloaded modules and packages.
GOROOT is —- C:Go-1.20 which is GoLang Binary (Go Software) installation directory.

Now I am going to execute “go install” command which will compiles and installs the packages named by the import paths.
Once you executed this command .exe file will be generated and copied to C:UsersRAMANATHANgobin directory.
That .exe file name will be same like module name.

We can execute that exe anywhere now.

If you want to uninstall the .exe simply delete the file in bin directory. Here i am deleting entire bin directory as i am having only one file.

These are the basic steps to Build, install and run Go Programs in Windows.

#go #goprogramming #golang #golangtutorial #golanguage #golangwindows #gowindows