Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to Install Golang in Termux?

  • Last Updated : 22 Sep, 2021

Termux is a command-line terminal emulator app for android built using JAVA language. It is built by Fredrik Fornwall. It has a Linux environment built within it, and it doesn’t require any rooting or separate setup to run the terminal emulator.

Go is a modern programming language built by Google Engineers. Go language is also called “Golang” and it was first released on November 10, 2009. Its syntax is somewhat similar to the C language. It is widely used for writing microservices.

To install Golang in the terminal, we have to follow the following steps :

Step 1: Download and install the termux from the play store, simply go through the following link and download the termux.

https://play.google.com/store/apps/details?id=com.termux&hl=en_IN&gl=US

Or, go through the following link to install Termux from F-droid.

https://f-droid.org/repo/com.termux_117.apk

Output:



Installing Termux

Step 2: Open up the termux app and run the following command to install Golang.

pkg install golang

Output:

Installing Golang on termux

Installing Golang on Termux

It will install the latest version of Golang in termux.

Step 3: Let’s create a  simple program in Golang:

open up the terminal emulator app and run the following command:

nano geeks.go

nano is a prebuilt text editor that comes with the installation of termux, running the above command will create a file named geeks with extension .go. Now paste the code written below and press Ctrl+X and confirm saving by typing Y.

Code:



Go




package main
    
import "fmt"
    
// Main function
func main() {
    
    fmt.Println("Welcome to GeeksforGeeks !!")
}

It will save the Golang hello world program.

Output:

Golang program

Golang program

Step 4: To compile and run the above program run the following command:

This command will compile the geeks.go program and results in an executable file.

go build geeks.go 

Output:

geeks executable file

geeks executable file

The file with green in color is the result of the above command, it is an executable file generated from geeks.go.

Step 5: To run the above program run the following command:

Simply “./” followed by file name to run the Golang program.

 ./geeks

Output:

Successfully compile and run the Golang program in termux

Successfully compile and run the Golang program in Termux




My Personal Notes arrow_drop_up
Recommended Articles
Page :