{"id":12771,"date":"2019-03-28T19:25:20","date_gmt":"2019-03-28T19:25:20","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12771"},"modified":"2019-03-28T19:25:20","modified_gmt":"2019-03-28T19:25:20","slug":"how-to-install-golang-go-programming-language-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/28\/how-to-install-golang-go-programming-language-in-linux\/","title":{"rendered":"How to Install GoLang (Go Programming Language) in Linux"},"content":{"rendered":"<p><strong>Go<\/strong>\u00a0(also referred to as\u00a0<strong>GoLang<\/strong>) is an open source and lower level programming language designed to enable users to easily write simple, reliable, and highly efficient computer programs.<\/p>\n<p>Developed in 2007 at\u00a0<strong>Google<\/strong>\u00a0by a team of programmers \u2013\u00a0<strong>Robert Griesemer<\/strong>,\u00a0<strong>Rob Pike<\/strong>, and\u00a0<strong>Ken Thompson<\/strong>, it is a compiled, statically typed language same as other system languages such as\u00a0<strong>C<\/strong>,\u00a0<strong>C++<\/strong>,\u00a0<strong>Java<\/strong>\u00a0and many more.<\/p>\n<p><strong>GoLang<\/strong>\u00a0is highly productive, and readable with support for networking and multiprocessing and it is scalable in extensive systems as well. Below is a list of a few well known open source projects developed using\u00a0<strong>GoLang<\/strong>:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/install-docker-and-learn-containers-in-centos-rhel-7-6\/\" target=\"_blank\" rel=\"noopener\">Docker<\/a><\/li>\n<li>Kubernetes<\/li>\n<li>Lime<\/li>\n<li>InfluxDB<\/li>\n<li>Gogs (Go Git Service) among others.<\/li>\n<\/ol>\n<h3>Install GoLang in Linux Systems<\/h3>\n<p><strong>1.<\/strong>\u00a0Go to\u00a0<a href=\"https:\/\/golang.org\/dl\/\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/golang.org\/dl\/<\/a>\u00a0and download the latest version (i.e\u00a0<strong>1.7.3<\/strong>) of GoLang in an archive file as follows:<\/p>\n<pre>$ cd ~\/Downloads\r\n$ wget -c https:\/\/storage.googleapis.com\/golang\/go1.7.3.linux-amd64.tar.gz<\/pre>\n<p><strong>2.<\/strong>\u00a0Next, check the integrity of the tarball by\u00a0<a href=\"https:\/\/www.tecmint.com\/generate-verify-check-files-md5-checksum-linux\/\" target=\"_blank\" rel=\"noopener\">verifying the SHA256 checksum of the archive file<\/a>\u00a0using the\u00a0<strong>shasum<\/strong>\u00a0command as below, where the flag\u00a0<code>-a<\/code>\u00a0is used to specify the algorithm to be used:<\/p>\n<pre>$ shasum -a 256 go1.7.3.linux-amd64.tar.gz\r\n\r\n<strong>ead40e884ad4d6512bcf7b3c7420dd7fa4a96140  go1.7.3.linux-amd64.tar.gz<\/strong>\r\n<\/pre>\n<p><strong>Important<\/strong>: To show that the contents of the downloaded archive file are the exact copy provided on the GoLang website, the\u00a0<strong>256-bit<\/strong>\u00a0hash value generated from the command above as seen in the output should be the same as that provided along with the download link.<\/p>\n<p>If that is the case, proceed to the next step, otherwise download a new tarball and run the check again.<\/p>\n<p><strong>3.<\/strong>\u00a0Then extract the tar archive files into\u00a0<strong>\/usr\/local<\/strong>\u00a0directory using the command below.<\/p>\n<pre>$ sudo tar -C \/usr\/local -xvzf go1.7.3.linux-amd64.tar.gz\r\n<\/pre>\n<p>Where,\u00a0<code>-C<\/code>\u00a0specifies the destination directory..<\/p>\n<h3>Configuring GoLang Environment in Linux<\/h3>\n<p><strong>4.<\/strong>\u00a0First, setup your\u00a0<strong>Go workspace<\/strong>\u00a0by creating a directory\u00a0<code>~\/go_projects<\/code>\u00a0which is the root of your workspace. The workspace is made of three directories namely:<\/p>\n<ol>\n<li><code>bin<\/code>\u00a0which will contain Go executable binaries.<\/li>\n<li><code>src<\/code>\u00a0which will store your source files and<\/li>\n<li><code>pkg<\/code>\u00a0which will store package objects.<\/li>\n<\/ol>\n<p>Therefore create the above directory tree as follows:<\/p>\n<pre>$ mkdir -p ~\/go_projects\/{bin,src,pkg}\r\n$ cd ~\/go_projects\r\n$ ls\r\n<\/pre>\n<p><strong>5.<\/strong>\u00a0Now it\u2019s time to execute\u00a0<strong>Go<\/strong>\u00a0like the rest of Linux programs without specifying its absolute path, its installation directory must be stored as one of the values of\u00a0<a href=\"https:\/\/www.tecmint.com\/set-path-variable-linux-permanently\/\" target=\"_blank\" rel=\"noopener\">$PATH environment variable<\/a>.<\/p>\n<p>Now, add\u00a0<code>\/usr\/local\/go\/bin<\/code>\u00a0to the\u00a0<strong>PATH<\/strong>\u00a0environment variable by inserting the line below in your\u00a0<strong>\/etc\/profile<\/strong>\u00a0file for a system-wide installation or\u00a0<strong>$HOME\/.profile<\/strong>\u00a0or\u00a0<strong>$HOME.\/bash_profile<\/strong>\u00a0for user specific installation:<\/p>\n<p>Using your preferred editor, open the appropriate user profile file as per your distribution and add the line below, save the file and exit:<\/p>\n<pre>export  PATH=$PATH:\/usr\/local\/go\/bin\r\n<\/pre>\n<p><strong>6.<\/strong>\u00a0Then, set the values of\u00a0<code>GOPATH<\/code>\u00a0and\u00a0<code>GOBIN<\/code>\u00a0Go environment variables in your user profile file (<strong>~\/.profile<\/strong>\u00a0or\u00a0<code>~\/bash_profile<\/code>) to point to your workspace directory.<\/p>\n<pre>export GOPATH=\"$HOME\/go_projects\"\r\nexport GOBIN=\"$GOPATH\/bin\"\r\n<\/pre>\n<p><strong>Note<\/strong>: If you installed\u00a0<strong>GoLang<\/strong>\u00a0in a custom directory other than the default (<strong>\/usr\/local\/<\/strong>), you must specify that directory as the value of\u00a0<strong>GOROOT<\/strong>\u00a0variable.<\/p>\n<p>For instance, if you have installed\u00a0<strong>GoLang<\/strong>\u00a0in home directory, add the lines below to your\u00a0<strong>$HOME\/.profile<\/strong>\u00a0or\u00a0<strong>$HOME\/.bash_profile<\/strong>\u00a0file.<\/p>\n<pre>export GOROOT=$HOME\/go\r\nexport PATH=$PATH:$GOROOT\/bin\r\n<\/pre>\n<p><strong>7.<\/strong>\u00a0The final step under this section is to effect the changes made to the user profile in the current bash session like so:<\/p>\n<pre>$ source ~\/.bash_profile\r\nOR\r\n$ source ~\/.profile\r\n<\/pre>\n<h3>Verify GoLang Installation<\/h3>\n<p><strong>8.<\/strong>\u00a0Run the commands below to view your\u00a0<strong>Go<\/strong>\u00a0version and environment:<\/p>\n<pre>$ go version\r\n$ go env\r\n<\/pre>\n<div id=\"attachment_23418\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/11\/Check-GoLang-Version.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23418\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/11\/Check-GoLang-Version.png\" alt=\"Check GoLang Version and Environment\" width=\"718\" height=\"382\" aria-describedby=\"caption-attachment-23418\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23418\" class=\"wp-caption-text\">Check GoLang Version and Environment<\/p>\n<\/div>\n<p>Type the following command to display usage information for\u00a0<strong>Go<\/strong>\u00a0tool, which manages\u00a0<strong>Go<\/strong>\u00a0source code:<\/p>\n<pre>$ go help\r\n<\/pre>\n<p><strong>9.<\/strong>\u00a0To test your if your\u00a0<strong>Go<\/strong>\u00a0installation is working correctly, write a small\u00a0<strong>Go hello<\/strong>\u00a0world program, save the file in\u00a0<strong>~\/go_projects\/src\/hello\/<\/strong>\u00a0directory. All your GoLang source files must end with the\u00a0<code>.go<\/code>\u00a0extension.<\/p>\n<p>Begin by creating the hello project directory under\u00a0<strong>~\/go_projects\/src\/<\/strong>:<\/p>\n<pre>$ mkdir -p ~\/go_projects\/src\/hello\r\n<\/pre>\n<p>Then use your favorite editor to create the\u00a0<code>hello.go<\/code>\u00a0file:<\/p>\n<pre>$ vi ~\/go_projects\/src\/hello\/hello.go\r\n<\/pre>\n<p>Add the lines below in the file, save it and exit:<\/p>\n<pre>package main \r\n\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n    fmt.Printf(\"Hello, you have successfully installed GoLang in Linux\\n\")\r\n}\r\n<\/pre>\n<p><strong>10.<\/strong>\u00a0Now, compile the program above as using\u00a0<strong>go<\/strong>\u00a0install and run it:<\/p>\n<pre>$ go install $GOPATH\/src\/hello\/hello.go\r\n$ $GOBIN\/hello\r\n<\/pre>\n<div id=\"attachment_23419\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/11\/Create-First-GoLang-Program.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23419\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/11\/Create-First-GoLang-Program.png\" alt=\"First GoLang Program\" width=\"718\" height=\"59\" aria-describedby=\"caption-attachment-23419\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23419\" class=\"wp-caption-text\">First GoLang Program<\/p>\n<\/div>\n<p>If you see the output showing you the message in the program file, then your installation is working correctly.<\/p>\n<p><strong>11.<\/strong>\u00a0To run your\u00a0<strong>Go<\/strong>\u00a0binary executables like other Linux commands, add\u00a0<strong>$GOBIN<\/strong>\u00a0to your\u00a0<strong>$PATH<\/strong>\u00a0environment variable.<\/p>\n<p><strong>Reference Links<\/strong>:\u00a0<a href=\"https:\/\/golang.org\/\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/golang.org\/<\/a><\/p>\n<p>That\u2019s it! You can now go on and learn\u00a0<strong>GoLang<\/strong>\u00a0for writing simple, reliable, and highly efficient computer programs. Are you already make use of GoLang?<\/p>\n<p>Share your experience with us and many other Linux users out there via the comment section below or imaginably, you can ask a question in relation to this guide or GoLang.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/install-go-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go\u00a0(also referred to as\u00a0GoLang) is an open source and lower level programming language designed to enable users to easily write simple, reliable, and highly efficient computer programs. Developed in 2007 at\u00a0Google\u00a0by a team of programmers \u2013\u00a0Robert Griesemer,\u00a0Rob Pike, and\u00a0Ken Thompson, it is a compiled, statically typed language same as other system languages such as\u00a0C,\u00a0C++,\u00a0Java\u00a0and many &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/28\/how-to-install-golang-go-programming-language-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Install GoLang (Go Programming Language) in Linux&#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-12771","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\/12771","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=12771"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12771\/revisions"}],"predecessor-version":[{"id":12772,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12771\/revisions\/12772"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}