{"id":45493,"date":"2024-02-07T15:29:23","date_gmt":"2024-02-07T15:29:23","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=45493"},"modified":"2026-02-16T03:38:53","modified_gmt":"2026-02-16T03:38:53","slug":"how-to-install-go-golang-1-22-in-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2024\/02\/how-to-install-go-golang-1-22-in-ubuntu-22-04\/","title":{"rendered":"How to Install GO (golang 1.26) in Ubuntu 24.04 | 22.04"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-logo.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-45494\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-logo-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-logo-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-logo-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-logo-700x700.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-logo-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-logo.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>Go programming language announced the new 1.26 release on 10 February, 2026! Here&#8217;s the new features and how to install guide for Ubuntu &amp; other Linux.<\/p>\n<h3>What&#8217;s New in Go 1.26:<\/h3>\n<ul>\n<li>The built-in new function, which creates a new variable, now allows its operand to be an expression.<\/li>\n<li>Generic types may now refer to themselves in their own type parameter list.<\/li>\n<li>Completely rewritten <code>go fix<\/code> command.<\/li>\n<li>Deleted <code>go tool doc<\/code>, use <code>go doc<\/code> as a replacement.<\/li>\n<li>The pprof tool web UI, enabled with the -http flag, now defaults to the flame graph view.<\/li>\n<li>The Green Tea garbage collector is now enabled by default.<\/li>\n<li>Reduce the baseline runtime overhead of cgo calls by ~30%.<\/li>\n<li>Randomizes the heap base address at startup on 64-bit platform.<\/li>\n<li>New experimental profile type that reports leaked goroutines.<\/li>\n<li>Compiler can now allocate the backing store for slices on the stack in more situations.<\/li>\n<li>The linker now supports internal linking mode of cgo programs on 64-bit Windows on ARM.<\/li>\n<li>Requires Go 1.24.6 or later for bootstrap.<\/li>\n<li>New crypto\/hpke package.<\/li>\n<li>New experimental simd\/archsimd package.<\/li>\n<li>New experimental runtime\/secret package<\/li>\n<\/ul>\n<p>See the <a href=\"https:\/\/go.dev\/doc\/go1.26\" target=\"_blank\" rel=\"noopener\">announcement<\/a> for more changes in Go 1.26.<\/p>\n<p><!--more--><\/p>\n<h3>How to Install Golang 1.26 in Ubuntu<\/h3>\n<h4>1. Download the Linux Tarball<\/h4>\n<p>Go provides official Linux tarball for i386, amd64, arm64, and armv6l CPU architecture types. They are available to download at the link below:<\/p>\n<div class=\"wp-block-buttons aligncenter\">\n<div class=\"wp-block-button is-style-fill\"><a class=\"wp-block-button__link has-vivid-cyan-blue-to-vivid-purple-gradient-background has-text-color has-background\" href=\"https:\/\/go.dev\/dl\/\" target=\"_blank\" rel=\"noreferrer noopener\">Download GO<\/a><\/div>\n<\/div>\n<p>In case you don&#8217;t know your system architecture type, press Ctrl+Alt+T to open terminal and run <code>dpkg --print-architecture<\/code> command to tell.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-50609\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/download-go126-700x480.webp\" alt=\"\" width=\"610\" height=\"418\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/download-go126-700x480.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/download-go126-300x206.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/download-go126-768x526.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/download-go126.webp 1308w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p>Or, run command to download the Linux tarball from command line (use <code>amd64<\/code> package for modern Intel\/AMD for example):<\/p>\n<pre>cd ~\/Downloads &amp;&amp; wget -c https:\/\/go.dev\/dl\/go1.26.0.linux-amd64.tar.gz<\/pre>\n<p>As time goes on, Go lang may release newer versions when you see this tutorial. In the case, <strong>change the URL (usually the part of version number) in last command accordingly.<\/strong><\/p>\n<h4>2. Extract Go Tarball to \/usr\/local<\/h4>\n<p><b>NOTE: If you&#8217;re trying to update Go to newer version, it&#8217;s HIGHLY recommended to remove the old one (via command below) to avoid issues:<\/b><\/p>\n<pre>sudo rm -rf \/usr\/local\/go<\/pre>\n<p>After downloaded the tarball, open terminal (<code>Ctrl+Alt+T<\/code>), and run commands:<\/p>\n<ul>\n<li>Navigate to the folder that saved the tarball (usually Downloads folder):\n<pre>cd ~\/Downloads<\/pre>\n<\/li>\n<li>Then, extract the tarball to <code>\/usr\/local<\/code> directory:\n<pre>sudo tar -C \/usr\/local\/ -xzf go1.26.0.linux-amd64.tar.gz<\/pre>\n<p>Also <strong>replace package name <code>go1.26.0.linux-amd64.tar.gz<\/code> in the command according to which tarball you downloaded.<\/strong><\/li>\n<\/ul>\n<p>After successfully extracted the tarball, use <code>ls \/usr\/local<\/code> to verify. It will output a list of sub-folders including <code>go<\/code>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-50610\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/extract-go126-700x528.webp\" alt=\"\" width=\"610\" height=\"460\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/extract-go126-700x528.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/extract-go126-300x226.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/extract-go126.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<h4>3. Set PATH Environment Variable<\/h4>\n<p><b>a.) Add GOROOT to Your User PATH<\/b><\/p>\n<p>To let your Ubuntu system know where to find Go command, user can add it to the PATH. And, here <code>\/usr\/local\/go<\/code> is the GOROOT directory. You just need to add its <code>bin<\/code> sub-folder to the PATH.<\/p>\n<p>Without logging out, run the command below to set PATH environment, which <b>works until your close the terminal window or exit the command console<\/b>.<\/p>\n<pre>export PATH=$PATH:\/usr\/local\/go\/bin<\/pre>\n<p><b>To make it permanent,<\/b> open home folder, press Ctrl+H to view\/hide hidden files, then click edit the <b>.profile<\/b> file (or .bashrc). When file opens, add following lines and save it.<\/p>\n<pre># set PATH so it includes \/usr\/local\/go\/bin if it exists\r\nif [ -d \"\/usr\/local\/go\/bin\" ] ; then\r\n    PATH=\"\/usr\/local\/go\/bin:$PATH\"\r\nfi<\/pre>\n<p>This works for <strong>current user only<\/strong>, and applies in next login.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-profile.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45497\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-profile-700x416.webp\" alt=\"\" width=\"610\" height=\"363\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-profile-700x416.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-profile-300x178.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-profile-768x456.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-profile-1320x784.webp 1320w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-profile.webp 1394w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p><b>To set the PATH environment variable<\/b> for all users, create &amp; edit a config file under <code>\/etc\/profile.d<\/code> directory instead. To do so, run command:<\/p>\n<pre>sudo nano \/etc\/profile.d\/go.sh<\/pre>\n<p>Then, paste the same lines above. Press Ctrl+S to save, and Ctrl+X to exit. Also, log out and back in to apply.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go2path-system.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45498\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go2path-system-700x454.webp\" alt=\"\" width=\"610\" height=\"396\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go2path-system-700x454.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go2path-system-300x195.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go2path-system-768x498.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go2path-system.webp 822w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p><b>b.) Add GOPATH to Your User PATH<\/b><\/p>\n<p>Running <code>go install<\/code> command by default downloads &amp; installs packages to <code>go<\/code> sub-folder (<i>create automatically if not exist<\/i>) in user home. It&#8217;s called GOPATH.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/gopath.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45765\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/gopath-700x344.webp\" alt=\"\" width=\"610\" height=\"300\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/gopath-700x344.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/gopath-300x148.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/gopath-768x378.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/gopath.webp 1208w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>If you want to change GOPATH to another directory, for example <code>.local\/go<\/code>, either use command below that works for current terminal or current command console:<\/p>\n<pre>export GOPATH=$HOME\/.local\/go<\/pre>\n<p>Or, edit the <b>.profile<\/b> file in user home and add the line in the end to make it permanent at next login.<\/p>\n<p><b>To add GOPATH to your user PATH<\/b>, here use the default GOPATH for example, either run command for current command console only:<\/p>\n<pre>export PATH=$PATH:$HOME\/go\/bin<\/pre>\n<p>Or, edit the <b>.profile<\/b> file and add following lines:<\/p>\n<pre># Add GOPATH to PATH if it exists\r\nif [ -d \"$HOME\/go\/bin\" ] ; then\r\n    PATH=\"$HOME\/go\/bin:$PATH\"\r\nfi<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/set-goenv.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45766\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/set-goenv-700x380.webp\" alt=\"\" width=\"610\" height=\"331\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/set-goenv-700x380.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/set-goenv-300x163.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/set-goenv-768x417.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/set-goenv-1320x717.webp 1320w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/set-goenv.webp 1476w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p><b>NOTE: The GOPATH directory may NOT exist out-of-the-box. You need to log out and back in to apply it to user PATH on the folder creation (usually first time running <code>go install<\/code> command).<\/b><\/p>\n<p>Golang also has many other environment options, you may run <b>go env<\/b> command to print them, and run similar commands above to change the directories.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-env.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-45767\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-env-700x505.webp\" alt=\"\" width=\"610\" height=\"440\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-env-700x505.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-env-300x217.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-env-768x555.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-env.webp 813w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Create your First Go program<\/h3>\n<p>When done setting PATH Environment Variable, you can run command to verify go version:<\/p>\n<pre>go version<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-50611\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go126-version-700x421.webp\" alt=\"\" width=\"610\" height=\"367\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go126-version-700x421.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go126-version-300x181.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go126-version.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p>To create your first Go project, say <b>hello<\/b>, do following commands one by one:<\/p>\n<ul>\n<li>First, create a project folder named &#8216;hello&#8217; and navigate into that folder.\n<pre>mkdir hello &amp;&amp; cd hello<\/pre>\n<p>Then, initialize new module (here use <code>example\/hello<\/code> as module name) in current directory to create a <code>go.mod<\/code> file to manage dependency.<\/p>\n<pre>go mod init example\/hello<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-init.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-48123\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-init-700x144.webp\" alt=\"\" width=\"610\" height=\"125\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-init-700x144.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-init-300x62.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-init-768x158.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-init.webp 858w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/li>\n<li>Now, let&#8217;s create new file, <code>hello.go<\/code> for example, with your favorite text editor:\n<pre>nano hello.go<\/pre>\n<p>Then, add the first code and save it (<i>For nano, press Ctrl+S then Ctrl+X<\/i>):<\/p>\n<pre>package main\r\n\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n    fmt.Println(\"Hello, World!\")\r\n}<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/nano-hellogo-1.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-48124\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/nano-hellogo-1-700x522.webp\" alt=\"\" width=\"610\" height=\"455\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/nano-hellogo-1-700x522.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/nano-hellogo-1-300x224.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/nano-hellogo-1.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/li>\n<li>Finally, either use <code>go run hello.go<\/code> command to run it. Or <code>go build hello.go<\/code> to build into a binary file.<a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-run-build.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-48125\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-run-build-700x389.webp\" alt=\"\" width=\"610\" height=\"339\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-run-build-700x389.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-run-build-300x167.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/02\/go-run-build.webp 754w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/li>\n<\/ul>\n<h3>Uninstall Go<\/h3>\n<p>To uninstall golang, simply delete the go directory under \/usr\/local by running command:<\/p>\n<pre>sudo rm -rf \/usr\/local\/go<\/pre>\n<p>That&#8217;s it.<\/p>","protected":false},"excerpt":{"rendered":"<p>Go programming language announced the new 1.26 release on 10 February, 2026! Here&#8217;s the new features and how to install guide for Ubuntu &amp; other Linux. What&#8217;s New in Go 1.26: The built-in new function, which creates a new variable, now allows its operand to be an expression. Generic types may now refer to themselves [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":45494,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,6],"tags":[2147],"class_list":["post-45493","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-news","tag-golang"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/45493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=45493"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/45493\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/45494"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=45493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=45493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=45493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}