Andrew Gerrand | 5bc444d | 2014-12-10 11:35:11 +1100 | [diff] [blame] | 1 | # Introduction |
Ihor Dvoretskyi | df806fa | 2016-03-03 15:26:44 -0800 | [diff] [blame] | 2 | This tutorial will show you how to install/build/run go on chrome OS. I have tested this using a Chromebook Pixel, however I do not have any other types of Chromebooks. However, this should work as long as you install the corresponding Linux package for your processor. |
Andrew Gerrand | 5bc444d | 2014-12-10 11:35:11 +1100 | [diff] [blame] | 3 | |
| 4 | # Requirements |
Filippo Valsorda | 2c0e582 | 2017-10-31 16:05:50 -0400 | [diff] [blame] | 5 | Your Chromebook must be in developer mode for this to work. Also please note this has only been tested on a 64gb LTE Pixel, however it should work on other Chromebooks. Note that enabling developer mode reduces the security guarantees offered by Chrome OS. |
Andrew Gerrand | 5bc444d | 2014-12-10 11:35:11 +1100 | [diff] [blame] | 6 | |
| 7 | # Install Go |
nathany | 5a0e590 | 2014-12-10 20:28:47 -0800 | [diff] [blame] | 8 | First download the latest version of Go for Linux-amd64 from the [Go Downloads page](http://golang.org/dl/) after that open a shell by hitting (Crtl+alt+t) and typing in "shell" then hit enter. Then extract it using the following command. |
Dave Day | 0d6986a | 2014-12-10 15:02:18 +1100 | [diff] [blame] | 9 | |
| 10 | ``` |
| 11 | sudo tar -C /usr/local -xzf ~/Downloads/FILENAMEHERE |
| 12 | ``` |
| 13 | |
| 14 | Go should now be installed you can test this by typing "/usr/local/go/bin/go" if it installed you should see the go help prompt. Congrats Go is now installed however you will not be able to run anything because chrome mounts partitions with noexec. The following will guide you through remounting your home folder, and setting up paths that are persistent across reboots, and shell sessions. |
Andrew Gerrand | 5bc444d | 2014-12-10 11:35:11 +1100 | [diff] [blame] | 15 | |
| 16 | # Create a Workspace |
| 17 | To keep this simple just create a folder called "gocode" in your downloads folder. Also create a folder called "src" inside. |
| 18 | |
| 19 | # Set Paths & Exec |
| 20 | Either type the following into your shell each session or if you want it to be persistent between sessions add it to your "~/.bashrc" file. The last line remounts your user folder so that you can run your go code other wise you would get permission errors. |
| 21 | ``` |
Andrew Gerrand | 5bc444d | 2014-12-10 11:35:11 +1100 | [diff] [blame] | 22 | export PATH=$PATH:/usr/local/go/bin |
Ihor Dvoretskyi | af014e2 | 2018-02-23 07:46:13 -0800 | [diff] [blame] | 23 | export GOPATH=~/Downloads/go |
Andrew Gerrand | 5bc444d | 2014-12-10 11:35:11 +1100 | [diff] [blame] | 24 | export PATH=$PATH:$GOPATH/bin |
| 25 | sudo mount -i -o remount,exec /home/chronos/user/ |
| 26 | ``` |
| 27 | This will allow you to run your go object files in your shell. |
| 28 | |
| 29 | # Test If It Worked |
| 30 | First add a "hello" folder inside of your "gocode/src" folder. After that create a file in your "gocode/src/hello" folder called "hello.go" with the following in it. Then run "go install hello" then "hello" and you should see "Hello, chrome os" in the console. |
Dave Day | 0d6986a | 2014-12-10 15:02:18 +1100 | [diff] [blame] | 31 | ```go |
Andrew Gerrand | 5bc444d | 2014-12-10 11:35:11 +1100 | [diff] [blame] | 32 | package main |
| 33 | |
| 34 | import "fmt" |
| 35 | |
| 36 | func main() { |
Dave Day | 0d6986a | 2014-12-10 15:02:18 +1100 | [diff] [blame] | 37 | fmt.Printf("Hello, chrome os\n") |
| 38 | } |
| 39 | ``` |