Andrew Gerrand | 5bc444d | 2014-12-10 11:35:11 +1100 | [diff] [blame] | 1 | # Introduction |
Ali Yousefi Sabzevar | 00bfb64 | 2019-02-18 13:54:13 +0100 | [diff] [blame] | 2 | #### EDIT: You don't need to compile from source in Developer mode, you can just use the [Chromebrew](https://github.com/skycocker/chromebrew)-provided version. |
James Larrowe | fe2fdd9 | 2019-02-10 18:34:45 -0500 | [diff] [blame] | 3 | #### EDIT2: If your Chromebook is relatively new, you can enable the Linux VM now built into ChromeOS to install Go without developer mode. Follow the steps from the following Google Support article to enable this feature- https://support.google.com/chromebook/answer/9145439. This has been tested on a Samsung Chromebook Plus on version 71.0.3578.127. If this feature is not available for you, you will need to enable Developer Mode. |
gidoBOSSftw5731 | f88098c | 2018-08-09 04:55:47 -0400 | [diff] [blame] | 4 | |
James Larrowe | 63f5ac7 | 2019-02-10 18:34:29 -0500 | [diff] [blame] | 5 | This tutorial will show you how to install, build, and run Go on Chrome OS. |
| 6 | 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] | 7 | |
| 8 | # Install Go |
James Larrowe | 63f5ac7 | 2019-02-10 18:34:29 -0500 | [diff] [blame] | 9 | First download the latest version of Go for Linux from the [Go Downloads page](http://golang.org/dl/). |
James Larrowe | 1dd6c33 | 2019-02-10 18:35:54 -0500 | [diff] [blame] | 10 | After that, open a shell by hitting (CTRL+ALT+T) and typing in `shell` then hit enter. Then extract it using the following command (when replacing `< Go Linux package >` with the name of the file you downloaded): |
Dave Day | 0d6986a | 2014-12-10 15:02:18 +1100 | [diff] [blame] | 11 | |
| 12 | ``` |
James Larrowe | 63f5ac7 | 2019-02-10 18:34:29 -0500 | [diff] [blame] | 13 | sudo tar xpvf ~/Downloads/< Go Linux package > -C /usr/local |
Dave Day | 0d6986a | 2014-12-10 15:02:18 +1100 | [diff] [blame] | 14 | ``` |
| 15 | |
James Larrowe | 1dd6c33 | 2019-02-10 18:35:54 -0500 | [diff] [blame] | 16 | Go should now be installed you can test this by typing `/usr/local/go/bin/go`. If it installed correctly, you should see the Go help prompt. Go is now installed. |
Andrew Gerrand | 5bc444d | 2014-12-10 11:35:11 +1100 | [diff] [blame] | 17 | |
| 18 | # Create a Workspace |
James Larrowe | 63f5ac7 | 2019-02-10 18:34:29 -0500 | [diff] [blame] | 19 | To keep this simple just create a folder called `/usr/local/go/work`. Also, create a folder called `src` inside `/usr/local/go`. |
Andrew Gerrand | 5bc444d | 2014-12-10 11:35:11 +1100 | [diff] [blame] | 20 | |
James Larrowe | 63f5ac7 | 2019-02-10 18:34:29 -0500 | [diff] [blame] | 21 | # Set PATH |
| 22 | Add the following to `~/.bashrc`: |
Andrew Gerrand | 5bc444d | 2014-12-10 11:35:11 +1100 | [diff] [blame] | 23 | ``` |
James Larrowe | 63f5ac7 | 2019-02-10 18:34:29 -0500 | [diff] [blame] | 24 | export GOPATH="/usr/local/go/work" |
| 25 | export PATH="${PATH}:/usr/local/go/bin:${GOPATH}/bin" |
Andrew Gerrand | 5bc444d | 2014-12-10 11:35:11 +1100 | [diff] [blame] | 26 | ``` |
James Larrowe | 63f5ac7 | 2019-02-10 18:34:29 -0500 | [diff] [blame] | 27 | This will allow you to run your Go programs in your shell. |
Andrew Gerrand | 5bc444d | 2014-12-10 11:35:11 +1100 | [diff] [blame] | 28 | |
James Larrowe | 63f5ac7 | 2019-02-10 18:34:29 -0500 | [diff] [blame] | 29 | # Test if it worked |
| 30 | First create a folder inside of your `/usr/local/go/src` folder. After that create a file in your folder called `hello.go` with the following in it: |
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() { |
James Larrowe | 63f5ac7 | 2019-02-10 18:34:29 -0500 | [diff] [blame] | 37 | fmt.Printf("Hello, Chrome OS!\n") |
Dave Day | 0d6986a | 2014-12-10 15:02:18 +1100 | [diff] [blame] | 38 | } |
James Larrowe | 63f5ac7 | 2019-02-10 18:34:29 -0500 | [diff] [blame] | 39 | ``` |
James Larrowe | 1dd6c33 | 2019-02-10 18:35:54 -0500 | [diff] [blame] | 40 | Now, run `go install hello`. Then, run `${GOPATH}/bin/hello` and you should see `Hello, Chrome OS!`. |
James Larrowe | 63f5ac7 | 2019-02-10 18:34:29 -0500 | [diff] [blame] | 41 | *** |
| 42 | |
| 43 | # Reporting bugs |
| 44 | Please go to [Issues](https://github.com/golang/go/issues) to report any issues you have. |