2021-01-05 02:18:00 +08:00
# asdf-golang
2023-07-19 05:23:13 +08:00
[![CI ](https://github.com/asdf-community/asdf-golang/actions/workflows/main.yml/badge.svg )](https://github.com/asdf-community/asdf-golang/actions/workflows/main.yml)
2016-08-30 10:01:14 +08:00
2018-02-23 23:00:42 +08:00
golang plugin for [asdf version manager ](https://github.com/asdf-vm/asdf )
2016-02-29 15:23:40 +08:00
2018-02-26 02:30:34 +08:00
## Requirements
2021-01-05 02:18:00 +08:00
### MacOS
2022-12-17 12:34:04 +08:00
* [GNU Core Utils ](http://www.gnu.org/software/coreutils/coreutils.html ) - `brew install coreutils`
2021-01-05 02:18:00 +08:00
### Linux (Debian)
2022-12-17 12:34:04 +08:00
* [GNU Core Utils ](http://www.gnu.org/software/coreutils/coreutils.html ) - `apt install coreutils`
* [curl ](https://curl.haxx.se ) - `apt install curl`
2018-02-26 02:30:34 +08:00
2016-02-29 15:23:40 +08:00
## Install
2021-01-05 02:18:00 +08:00
```bash
2023-07-19 05:23:13 +08:00
asdf plugin add golang https://github.com/asdf-community/asdf-golang.git
2016-02-29 15:23:40 +08:00
```
## Use
2018-02-23 23:00:42 +08:00
Check the [asdf ](https://github.com/asdf-vm/asdf ) readme for instructions on how to install & manage versions of go.
2016-02-29 15:23:40 +08:00
2023-05-09 22:40:46 +08:00
## `GOROOT`
To set `GOROOT` in your shell's initialization add the following:
**zsh shell**
`. ~/.asdf/plugins/golang/set-env.zsh`
2023-05-24 09:13:26 +08:00
**fish shell**
2024-01-30 01:35:21 +08:00
`source ~/.asdf/plugins/golang/set-env.fish`
2023-05-24 09:13:26 +08:00
2024-04-19 20:14:03 +08:00
**nushell shell**
Add this to your env.nu
`source ('~/.asdf/plugins/golang/set-env.nu')`
2024-09-25 09:01:27 +08:00
**bash shell**
Add this to your .bashrc:
`. ~/.asdf/plugins/golang/set-env.bash`
2022-03-01 03:46:41 +08:00
## When using `go get` or `go install`
2019-09-11 10:57:17 +08:00
2022-03-01 03:46:41 +08:00
After using `go get` or `go install` to install a package you need to run `asdf reshim golang` to get any new shims.
2019-09-11 10:57:17 +08:00
2020-06-17 06:11:29 +08:00
### Default `go get` packages
asdf-golang can automatically install a default set of packages with `go get -u $PACKAGE` right after installing a new Go version.
To enable this feature, provide a \$HOME/.default-golang-pkgs file that lists one package per line, for example:
2021-01-05 02:18:00 +08:00
```bash
2020-06-17 06:11:29 +08:00
// allows comments
github.com/Dreamacro/clash
github.com/jesseduffield/lazygit
```
2021-09-10 02:14:08 +08:00
You can specify a non-default location of this file by setting a `ASDF_GOLANG_DEFAULT_PACKAGES_FILE` variable.
2021-06-16 20:04:20 +08:00
## Version selection
When using `.tool-versions` or `.go-version` , the exact version specified in the
file will be selected.
When using `go.mod` , the highest compatible version that is currently installed
will be selected. As per the [Go modules
reference](https://golang.org/ref/mod#go-mod-file-go), that is the highest minor
version with a matching major version. For example, a `go 1.14` directive in a
`go.mod` file will result in the highest installed `1.minor.patch` being
selected, not necessarily `1.14.patch` .
2023-05-12 02:37:45 +08:00
**Note**: Users can explicitly exclude or include `go.mod` and `go.work` by
setting `ASDF_GOLANG_MOD_VERSION_ENABLED` . Currently it defaults to `true` , but that
may change in the future, so it should be explicitly set.
2021-10-29 05:03:53 +08:00
## Architecture Override
2022-12-17 12:34:04 +08:00
The `ASDF_GOLANG_OVERWRITE_ARCH` variable can be used to override the architecture
that is used for determining which Go build to download. The primary use case is when attempting
2021-10-29 05:03:53 +08:00
to install an older version of Go for use on an Apple M1 computer as Go was not being built for ARM at the time.
2022-12-17 13:10:23 +08:00
2021-10-29 05:03:53 +08:00
#### Without ASDF_GOLANG_OVERWRITE_ARCH
2022-12-17 13:10:23 +08:00
2021-10-29 05:03:53 +08:00
```
> asdf install golang 1.15.8
Platform 'darwin' supported!
2022-12-17 12:34:04 +08:00
URL: https://dl.google.com/go/go1.15.8.darwin-arm64.tar.gz returned status 404
2021-10-29 05:03:53 +08:00
```
#### With ASDF_GOLANG_OVERWRITE_ARCH
2022-12-17 13:10:23 +08:00
2021-10-29 05:03:53 +08:00
```
> ASDF_GOLANG_OVERWRITE_ARCH=amd64 asdf install golang 1.15.8
Platform 'darwin' supported!
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 116M 100 116M 0 0 98.6M 0 0:00:01 0:00:01 --:--:-- 98.6M
verifying checksum
/Users/< home > /.asdf/downloads/golang/1.15.8/archive.tar.gz: OK
checksum verified
```
2022-12-17 13:10:23 +08:00
## Skipping Checksums
2023-07-19 05:23:13 +08:00
By default we try to verify the checksum of each install but ocassionally [that's not possible ](https://github.com/asdf-community/asdf-golang/issues/91 ).
2022-12-17 13:10:23 +08:00
If you need to skip the checksum for some reason just set `ASDF_GOLANG_SKIP_CHECKSUM` .
2016-02-29 15:23:40 +08:00
## Contributing
Feel free to create an issue or pull request if you find a bug.
## Issues
2022-12-17 12:34:04 +08:00
* Assumes Linux, FreeBSD, or Mac
* Assumes x86_64, i386, i686, armv6l, armv7l, arm64 and ppc64le
2016-02-29 15:23:40 +08:00
## License
2021-01-05 02:18:00 +08:00
2016-02-29 15:23:40 +08:00
MIT License