github.com/ungtb10d/cli/v2@v2.0.0-20221110210412-98537dd9d6a1/docs/source.md (about) 1 # Installation from source 2 3 1. Verify that you have Go 1.18+ installed 4 5 ```sh 6 $ go version 7 ``` 8 9 If `go` is not installed, follow instructions on [the Go website](https://golang.org/doc/install). 10 11 2. Clone this repository 12 13 ```sh 14 $ git clone https://github.com/ungtb10d/cli.git gh-cli 15 $ cd gh-cli 16 ``` 17 18 3. Build and install 19 20 #### Unix-like systems 21 ```sh 22 # installs to '/usr/local' by default; sudo may be required, or sudo -E for configured go environments 23 $ make install 24 25 # or, install to a different location 26 $ make install prefix=/path/to/gh 27 ``` 28 29 #### Windows 30 ```pwsh 31 # build the `bin\gh.exe` binary 32 > go run script\build.go 33 ``` 34 There is no install step available on Windows. 35 36 4. Run `gh version` to check if it worked. 37 38 #### Windows 39 Run `bin\gh version` to check if it worked. 40 41 ## Cross-compiling binaries for different platforms 42 43 You can use any platform with Go installed to build a binary that is intended for another platform 44 or CPU architecture. This is achieved by setting environment variables such as GOOS and GOARCH. 45 46 For example, to compile the `gh` binary for the 32-bit Raspberry Pi OS: 47 ```sh 48 # on a Unix-like system: 49 $ GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=0 make clean bin/gh 50 ``` 51 ```pwsh 52 # on Windows, pass environment variables as arguments to the build script: 53 > go run script\build.go clean bin\gh GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=0 54 ``` 55 56 Run `go tool dist list` to list all supported values of GOOS/GOARCH. 57 58 Tip: to reduce the size of the resulting binary, you can use `GO_LDFLAGS="-s -w"`. This omits 59 symbol tables used for debugging. See the list of [supported linker flags](https://golang.org/cmd/link/).