Where are globally-installed Go tools located & how to execute them (when using Go similarly to 'npm install -g')
Jun 2, 2021 08:40 · 220 words · 2 minute read
With some command line tools written in Go (like scc, a tool for counting a project’s lines of code), you’ll see install instructions like this:
|
|
But where is this package installed, how do you actually execute the command then? TLDR: In this case, the binary will be stored in /home/<USER>/go/bin/scc
.
Packages like this are installed into your GOPATH
. Some people will have already set up an environment value GOPATH
, and thus echo $GOPATH
will output this path. The binary is then stored in GOPATH/bin
. But: If you have mostly used Go mostly with the newer “modules” feature, it is likely that you didn’t have a need to set this up. Then, Go will use a default GOPATH
value, and you can find it out with go env GOPATH
. Most likely, it will be /home/<USER>/go
.
If you using tools like this often, it might make sense to add this folder to your PATH
, so you can simply execute scc
instead of having to specify the full path like /home/markus/go/bin/scc
. For this, add this line to the end of your .bashrc
/.zshrc
:
|
|
Note: If your current working directory (where you executed go get
) contains a go.mod
file, the package will get added to the go.mod
file. But it will still be available in your GOPATH/bin
.
- You are in control
- My Favorite Shortcuts for VS Code
- Customizing my shell: From bash to zsh to fish
- JSON5: JSON with comments (and more!)
- jq: Analyzing JSON data on the command line
- Get Total Directory Size via Command Line
- Changing DNS server for Huawei LTE router
- Notes on Job & Career Development
- Adding full-text search to a static site (= no backend needed)
- Generating a random string on Linux & macOS