{"id":969,"date":"2018-10-19T18:56:08","date_gmt":"2018-10-19T18:56:08","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=969"},"modified":"2018-10-23T01:06:21","modified_gmt":"2018-10-23T01:06:21","slug":"how-to-install-and-test-go-on-centos","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/19\/how-to-install-and-test-go-on-centos\/","title":{"rendered":"How To Install And Test Go On CentOS"},"content":{"rendered":"<p>Go also known as golang, is a compiled computer programming language developed by google. It is loosely based on the C language but designed to overcome some of its short comings. It is a general purpose language and can be used from server-side development to games and streaming media. It can easily be installed on a CentOS system. This guide assumes you have at least a basic working installation of a Linux system.<\/p>\n<h2>Install Go on CentOS<\/h2>\n<p>Clean up repositories<\/p>\n<p>yum clean all<\/p>\n<p>Ensure everything is up to date<\/p>\n<p>yum update<\/p>\n<p>Change directories<\/p>\n<p>cd \/usr\/src<\/p>\n<p>Download the compiled package, you can find the most recent release on the <a href=\"https:\/\/golang.org\/dl\/\">downloads page<\/a>.<\/p>\n<p>wget https:\/\/storage.googleapis.com\/golang\/go1.8.3.linux-amd64.tar.gz<\/p>\n<p>Uncompress the archive<\/p>\n<p>tar xfvz go1.8.3.linux-amd64.tar.gz<\/p>\n<p>Move the binary and its applicable files to \/usr\/local<\/p>\n<p>mv go \/usr\/local\/<\/p>\n<p>Export the following<\/p>\n<p>export GOROOT=\/usr\/local\/go<\/p>\n<p>GOROOT defines the path you placed the Go package in<\/p>\n<p>export GOPATH=$HOME\/go-project<\/p>\n<p>GOPATH tells go where your project is located, this can be anywhere<\/p>\n<p>export PATH=$GOPATH\/bin:$GOROOT\/bin:$PATH<\/p>\n<p>This appends both the GOPATH and GOROOT to your $PATH. You can also add this to your .bash_profile to automatically export these variables upon logging in.<\/p>\n<h2>Verify Go Installation<\/h2>\n<p>By typing \u2018go version\u2019 it will give you a print out of the version you currently have running<\/p>\n<p># go version<br \/>\ngo version go1.8.3 linux\/amd64<\/p>\n<p>By typing \u2018go env\u2019 it will show the environment variables that are currently in use.<\/p>\n<p># go env<br \/>\nGOARCH=&#8221;amd64&#8243;<br \/>\nGOBIN=&#8221;&#8221;<br \/>\nGOEXE=&#8221;&#8221;<br \/>\nGOHOSTARCH=&#8221;amd64&#8243;<br \/>\nGOHOSTOS=&#8221;linux&#8221;<br \/>\nGOOS=&#8221;linux&#8221;<br \/>\nGOPATH=&#8221;\/root\/go-project&#8221;<br \/>\nGORACE=&#8221;&#8221;<br \/>\nGOROOT=&#8221;\/usr\/local\/go&#8221;<br \/>\nGOTOOLDIR=&#8221;\/usr\/local\/go\/pkg\/tool\/linux_amd64&#8243;<br \/>\nGCCGO=&#8221;gccgo&#8221;<br \/>\nCC=&#8221;gcc&#8221;<br \/>\nGOGCCFLAGS=&#8221;-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=\/tmp\/go-build167939199=\/tmp\/go-build -gno-record-gcc-switches&#8221;<br \/>\nCXX=&#8221;g++&#8221;<br \/>\nCGO_ENABLED=&#8221;1&#8243;<br \/>\nPKG_CONFIG=&#8221;pkg-config&#8221;<br \/>\nCGO_CFLAGS=&#8221;-g -O2&#8243;<br \/>\nCGO_CPPFLAGS=&#8221;&#8221;<br \/>\nCGO_CXXFLAGS=&#8221;-g -O2&#8243;<br \/>\nCGO_FFLAGS=&#8221;-g -O2&#8243;<br \/>\nCGO_LDFLAGS=&#8221;-g -O2&#8243;<\/p>\n<h2>Test a Go project<\/h2>\n<p>Create the project directory you exported earlier:<\/p>\n<p>mkdir $HOME\/go-project<\/p>\n<p>Change to that directory:<\/p>\n<p>cd $HOME\/go-project<\/p>\n<p>Create a new file:<\/p>\n<p>nano hello.go<\/p>\n<p>Insert the following lines:<\/p>\n<p>package main<br \/>\nimport &#8220;fmt&#8221;<br \/>\nfunc main() {<br \/>\nfmt.Println(&#8220;hello world&#8221;)<br \/>\n}<\/p>\n<p>Execute the file:<\/p>\n<p>go run hello.go<\/p>\n<p>The file should print the following<\/p>\n<p># go run hello.go<br \/>\nhello world<\/p>\n<p>That\u2019s it, you should now have a working Go installation.<\/p>\n<p>Aug 7, 2017LinuxAdmin.io<\/p>\n<p><a href=\"https:\/\/linuxadmin.io\/install-go-centos\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go also known as golang, is a compiled computer programming language developed by google. It is loosely based on the C language but designed to overcome some of its short comings. It is a general purpose language and can be used from server-side development to games and streaming media. It can easily be installed on &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/19\/how-to-install-and-test-go-on-centos\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How To Install And Test Go On CentOS&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-969","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/969","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=969"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/969\/revisions"}],"predecessor-version":[{"id":1381,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/969\/revisions\/1381"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=969"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=969"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}