{"id":1333,"date":"2015-12-22T14:32:30","date_gmt":"2015-12-22T06:32:30","guid":{"rendered":"http:\/\/www.strongd.net\/?p=1333"},"modified":"2015-12-22T14:32:30","modified_gmt":"2015-12-22T06:32:30","slug":"building-go-1-5-on-the-raspberry-pi","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=1333","title":{"rendered":"Building Go 1.5 on the Raspberry Pi"},"content":{"rendered":"<p>This is a short post to describe my recommended method for building Go on the Raspberry Pi. This method has been tested on the Raspberry Pi 2 Model B (900Mhz, 1Gb ram) and the older Raspberry Pi 1 Model B+ (700Mhz, 512Mb ram).<\/p>\n<p>This method will build Go 1.5 into you home directory, <code>\/usr\/local\/go<\/code>.<\/p>\n<p>As always, <em>please<\/em> don\u2019t set <code>$GOROOT<\/code>. You never need to set <code>$GOROOT<\/code> when building from source.<\/p>\n<h2>Step 1.\u00a0Getting the bootstrap Go 1.4 compiler<\/h2>\n<p>Go 1.5 requires an existing Go 1.4 (or later) compiler to build Go 1.5.\u00a0If you have built Go from source on your host machine you can generate this tarball directly, but to save time <a href=\"http:\/\/www.strongd.net\/dl\/go\/go-linux-arm-bootstrap-c788a8e.tbz\">I\u2019ve done it\u00a0for you<\/a>.<\/p>\n<pre>% mkdir \/usr\/local\/go\r\n% <b>cd \/usr\/local\/go<\/b>\r\n% <b>curl http:\/\/www.strongd.net\/dl\/go\/go-linux-arm-bootstrap-c788a8e.tbz<b> | tar xj<\/b>\r\n<\/b><\/pre>\n<h2>Step 2. Fetch the Go 1.5 source<\/h2>\n<p>Fetch the Go 1.5 source tarball and unpack it to <code>\/usr\/local\/go<\/code><\/p>\n<pre>% <b>cd \/usr\/local\/go<\/b>\r\n% <b>curl https:\/\/storage.googleapis.com\/golang\/go1.5.src.tar.gz | tar xz<\/b><\/pre>\n<h2>Step 3. Configure your environment and build<\/h2>\n<p>Go 1.5 builds cleanly on arm devices, this is verified by the <a href=\"https:\/\/build.golang.org\/\">build dashboard<\/a>, however if you want to see <code>.\/all.bash<\/code> pass on the Raspberry Pi, some additional configuration is recommended.<\/p>\n<h4>Lower the default stack size from 8mb to 1mb.<\/h4>\n<p>This is necessary because the <code>runtime<\/code> tests create many native operating system threads which at 8mb per thread can exhaust the 32bit user mode address space (especially if you are running a recent Raspbian kernel). See issue <a href=\"https:\/\/github.com\/golang\/go\/issues\/11959\">11959<\/a>\u00a0for the details.<\/p>\n<pre>% <b>ulimit -s 1024     <\/b># set the thread stack limit to 1mb\r\n% <b>ulimit -s          <\/b># check that it worked\r\n1024<\/pre>\n<h4>Increase the scaling factor to avoid\u00a0test timeouts.<\/h4>\n<p>The default scaling factor is good for powerful amd64 machines, but is too aggressive for small 32 bit machines. This is done with the <code>GO_TEST_TIMEOUT_SCALE<\/code> environment variable.<\/p>\n<h1>Step 4. Build<\/h1>\n<pre>% <strong>cd \/usr\/local\/go\/src<\/strong>\r\n%<b> env GO_TEST_TIMEOUT_SCALE=10 GOROOT_BOOTSTRAP=\/usr\/local\/go\/go-linux-arm-bootstrap .\/all.bash<\/b>\r\n# Building C bootstrap tool.\r\ncmd\/dist\r\n\r\n# Building compilers and Go bootstrap tool for host, linux\/arm.\r\nlib9\r\nlibbio\r\nliblink\r\n...\r\n##### ..\/test\r\n\r\n##### API check\r\nGo version is \"go1.5\", ignoring -next \/home\/pi\/go\/api\/next.txt\r\n\r\nALL TESTS PASSED\r\n\r\n---\r\nInstalled Go for linux\/arm in \/usr\/local\/go\r\nInstalled commands in \/usr\/local\/go\/bin<\/pre>\n<p>On the Raspberry Pi 2 Model B, this should take around an hour, for the older Raspberry Pi 1 Model B+, it takes more than five!<\/p>\n<p>As a final step you should add <code>\/usr\/local\/go<\/code> to your <code>$PATH<\/code>,\u00a0and to save disk space you can remove\u00a0<code>\/usr\/local\/go\/go-linux-arm-bootstrap<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a short post to describe my recommended method for building Go on the Raspberry Pi. This method has been tested on the Raspberry Pi 2 Model B (900Mhz, 1Gb ram) and the older Raspberry Pi 1 Model B+ (700Mhz, 512Mb ram). This method will build Go 1.5 into you home directory, \/usr\/local\/go. As &hellip; <a href=\"https:\/\/www.strongd.net\/?p=1333\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Building Go 1.5 on the Raspberry Pi<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5,20],"tags":[198,199],"class_list":["post-1333","post","type-post","status-publish","format-standard","hentry","category-linux","category-5","category-20","tag-go","tag-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1333"}],"version-history":[{"count":1,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1333\/revisions"}],"predecessor-version":[{"id":1334,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1333\/revisions\/1334"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}