Uninstalling a package installed with Go

Hi, my name is Tina! I am a Full Stack Software Developer and Tech Lead from Canada. 🙋🏻♀️
Search for a command to run...

Hi, my name is Tina! I am a Full Stack Software Developer and Tech Lead from Canada. 🙋🏻♀️
No comments yet. Be the first to comment.
Overview This is the 3rd article in a series of posts about working with Open API to create generated API clients and documentation websites. In the 1st post we went over what we can do with Open API spec files, e.g. generate API clients and documen...

Overview This article is the 2nd in a series of blog posts that discuss using Open API to help with API documentation and API client code generation. In the previous article, we went over how we can generate documentation and API clients using existi...

Overview This article starts a series of Open API-related blog posts. OpenAPI, previously known as Swagger (a name still in use today for many of its tools), is a suite of tools that generate documentation and networking clients for various programmi...

You've probably already seen the scary alert (that's possibly why you're here), but in case you haven't, it looks something like this: NewAppIJustDownloaded pasted from your clipboard Sometimes it h

Have you ever installed a package by using go install <some-package> and wondered how to uninstall it?
Go is really great in that respect. Go packages are a single binary and they’re installed based on how your Go tooling is set up.
Provided we have Go installed, when we run go help install in the command line, we can see where packages are installed:
usage: go install [build flags] [packages]
Install compiles and installs the packages named by the import paths.
Executables are installed in the directory named by the GOBIN environment variable, which defaults to $GOPATH/bin or $HOME/go/bin if the GOPATH environment variable is not set. Executables in $GOROOT are installed in $GOROOT/bin or $GOTOOLDIR instead of $GOBIN.
So that’s pretty straight-forward. Let’s see where our packages are installed by trying the first command:
echo $GOPATH
If that returns blank, it’s not defined, so we can probably assume they’re going to be installed in ~/go/bin.
ls $HOME/go/bin
This should return a list of executable binaries installed using go install.
A while back, I built a really simple CLI tool to assist me with testing deep links and statically generated sites that I built. This CLI tool static-server allows me to serve the entire contents of a directory as a static website.
As the instructions in the README say, I can install the latest version of the tool using Go with the following command:
go install github.com/tinacious/static-server@latest
Then, I can navigate to any static HTML website folder on my computer and serve it. Let’s assume I have the following directory somewhere:
test
├── index.html
└── style.css
I can run the following:
cd path/to/test
static-server
This will serve the contents of the directory on a random port.
Let’s say you’ve tried this tool and you absolutely hate it. You prefer to type out the long Python 3 command, or use an NPM package that depends on you having the correct Node.js runtime on your computer. Here’s how you can uninstall static-server.
which static-server
This should output the path to the binary. Simply delete it.
Or, if you’re feeling brave and want to do it in a single line:
rm $(which static-server)