Coder Social home page Coder Social logo

goenv's Introduction

Goenv Logo

Goenv

Manage Your Applications Go Environment


Goenv helps you to work with multiple golang versions at the same time whether on mac or linux operating system. It supports both global and per-application version configuration.

Usage

Download the latest goenv binary. Make it executable from everywhere.

$ export GOENV_LATEST_VERSION=$(curl --silent "https://api.github.com/repos/norwik/Goenv/releases/latest" | jq '.tag_name' | sed -E 's/.*"([^"]+)".*/\1/' | tr -d v)

# For Linux
$ curl -sL https://github.com/norwik/Goenv/releases/download/v{$GOENV_LATEST_VERSION}/goenv_Linux_x86_64.tar.gz | tar xz

# For Mac
$ curl -sL https://github.com/norwik/Goenv/releases/download/v{$GOENV_LATEST_VERSION}/goenv_Darwin_x86_64.tar.gz | tar xz

Or install with homebrew

$ brew tap norwik/tools
$ brew install norwik/tools/goenv

Configure the goenv using the following command

$ goenv config

Add goenv shims to PATH using the following command. also append it to ~/.profile file to make it permanent.

$ export PATH="$HOME/.goenv/shims:"$PATH

# OR

$ eval "$(goenv init)"

Install a new go version 1.18 and set as a global

$ goenv install 1.18
$ goenv global 1.18

To configure a local version different from the global

$ goenv local 1.18

To Uninstall a version

$ goenv uninstall 1.18

Show the used version either from current directory or parent directories or the global version.

$ goenv version

To list all installed versions

$ goenv versions

for a list of all available commands

$ goenv --help

๐Ÿบ Manage Your Applications Go Environment.

If you have any suggestions, bug reports, or annoyances please report
them to our issue tracker at <https://github.com/norwik/goenv/issues>

Usage:
  goenv [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  config      Configure the goenv application.
  exec        Show the current go version.
  global      Set or show the global go version.
  help        Help about any command
  info        Print the goenv version
  init        Init the import path for goenv shims.
  install     Install a go version.
  license     Print the license
  local       Set or show the local application-specific go version.
  rehash      Refresh binaries under goenv shim directory.
  satisfy     Satisfy the current directry go version.
  uninstall   Uninstall a specific go version.
  version     Show the current go version.
  versions    List installed go versions.

Flags:
  -h, --help   help for goenv

Use "goenv [command] --help" for more information about a command.

Under The Hood

Goenv is inspired by and works like rbenv. At a high level, goenv intercepts Go commands using shim executables injected into your PATH, determines which Go version has been specified by your application or globally, and passes your commands to the correct Go installation bin folder.

Understanding PATH

When you run a command like go or gofmt, your operating system searches through a list of directories to find an executable file with that name. This list of directories lives in an environment variable called PATH, with each directory in the list separated by a colon:

/usr/local/bin:/usr/bin:/bin

Directories in PATH are searched from left to right, so a matching executable in a directory at the beginning of the list takes precedence over another one at the end. In this example, the /usr/local/bin directory will be searched first, then /usr/bin, then /bin.

Understanding Shims

goenv works by inserting a directory of shims at the front of your PATH:

~/.goenv/shims:/usr/local/bin:/usr/bin:/bin

Through a process called rehashing, goenv maintains shims in that directory to match every Go command across every installed version of go like gofmt and so on.

shims are lightweight executables that simply pass your command to the right binary under the current go version, your operating system will do the following:

  1. Search your PATH for an executable file named gofmt.
  2. Find the goenv shim named gofmt at the beginning of your PATH
  3. Run the shim named gofmt, which in turn fetch the target go version and use the gofmt inside go/bin directory.

Choosing the Go Version

When you execute a shim, goenv determines which Go version to use by reading it from the following sources, in this order:

  1. The first .go-version file found by searching the current working directory and each of its parent directories until reaching the root of your filesystem. You can modify the .go-version file in the current working directory with the goenv local x.x.x command.
  2. The global $HOME/.goenv/.go-version file. You can modify this file using the goenv global x.x.x command.

Versioning

For transparency into our release cycle and in striving to maintain backward compatibility, Goenv is maintained under the Semantic Versioning guidelines and release process is predictable and business-friendly.

See the Releases section of our GitHub project for changelogs for each release version of Goenv. It contains summaries of the most noteworthy changes made in each release. Also see the Milestones section for the future roadmap.

Bug tracker

If you have any suggestions, bug reports, or annoyances please report them to our issue tracker at https://github.com/norwik/goenv/issues

Security Issues

If you discover a security vulnerability within Goenv, please send an email to [email protected]

Contributing

We are an open source, community-driven project so please feel free to join us. see the contributing guidelines for more details.

License

ยฉ 2022, Clivern. Released under MIT License.

Goenv is authored and maintained by @clivern.

goenv's People

Contributors

clivern avatar dependabot[bot] avatar renovate[bot] avatar stack-file[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

goenv's Issues

How does this work?

I am confused about how this is meant to work, the picture should tell it all:

image

As you can see, the shims path is first, I have 1.19 installed correctly and set for both global and local, yet it still reverts to version 1.16 (the system version in /usr/bin)?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/build.yml
  • actions/checkout v4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • actions/setup-go v5
.github/workflows/release.yml
  • actions/checkout v4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • actions/setup-go v5
  • goreleaser/goreleaser-action v5
.github/workflows/release_package.yml
  • actions/checkout v4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • actions/setup-go v5
gomod
go.mod
  • go 1.18
  • github.com/charmbracelet/bubbles v0.16.0
  • github.com/charmbracelet/bubbletea v0.26.1
  • github.com/charmbracelet/lipgloss v0.6.0
  • github.com/franela/goblin v0.0.0-20211003143422-0a4f594942bf@0a4f594942bf
  • github.com/spf13/cobra v1.8.0

  • Check this box to trigger a request for Renovate to run again on this repository

Listing the Go versions available for install

Is your feature request related to a problem? Please describe.
Yes, I use a tool like nvm to manage my Node versions. In nvm we have a command nvm ls-remote which lists the Node versions that are available for install so that I can know what to install with the goenv install command and specifying the right version.

Describe the solution you'd like
A command like goenv ls-remote which will return the Go versions available for download and also marks which of the available Go versions have been installed locally by using a different coloring or another way to mark them as already installed, similar to what nvm ls-remote. It will also be good to mark the LTS versions of Go that are available for installation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.