Golang is a programming language developed by Google. Thanks to its versatility, simplicity and reliability, Golang has become one of the most popular programming languages in the open source community.
In this article, I will show you how to install the latest stable release of Golang on 64-bit Linux operating systems, in CentOS 7. At the time I wrote this article, the latest stable release of Golang was Golang 1.12.1
Step 1: Download and decompress the Golang 1.12.1 archive
if you are using a 64-bit Linux operating system, in CentOS 7 x64, you need to download the 64-bit version of Golang as below:
# cd |
# wget https://dl.google.com/go/go1.12.1.linux-amd64.tar.gz |
# tar -zxvf go1.12.1.linux-amd64.tar.gz -C /usr/local |
Note: You can always find the download link to the latest release of Golang on the golang official download page
Step 2: Setup GOROOT and PATH environment variables:
# echo 'export GOPATH=~/.go' | tee -a /etc/profile |
# echo 'export GOROOT=/usr/local/go' | tee -a /etc/profile |
# echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' | tee -a /etc/profile |
# source /etc/profile |
Step 3: Test the installation
# go version |
# go env |
In addition, you can write a simple Golang program and give it a shot:
# cd |
# mkdir -p src/hello |
# cd |
# vi hello.go |
Populate the file ~/src/hello/hello.go with the following code segment:
package main import "fmt" func main() { fmt.Printf("hello, world\n") } |
Save and quit:
:wq! |
Finally, run your first Golang program as follows:
# go run hello.go |
If everything was done correctly, you will see the output:
hello world |
This concludes my tutorial. Thanks for reading.
Tidak ada komentar:
Posting Komentar