How do I delete a package that I accidentally published to go.dev?

1.8k Views Asked by At

I accidentally published a package to go.dev website, can anyone tell me how to delete it?

https://pkg.go.dev/github.com/Nksama/Random-quotes

2

There are 2 best solutions below

0
blami On

There's package removal guide on the site: https://go.dev/about/

Basically you need to put retract directive in your go.mod file and publish new version.

0
Shailesh Suryawanshi On

Published modules cannot be deleted but can be retracted. A retracted version still exists and can be downloaded (so builds that depend on it won't break), but the go command won’t select it automatically when resolving. More info here.

To retract you will have to add retract directive to your go.mod. For example

retract v1.0.0
retract [v1.0.0, v1.9.9]
retract (
    v1.0.0
    [v1.0.0, v1.9.9]
)

Please Note :

The retract directive was added in Go 1.16. Go 1.15 and lower will report an error if a retract directive is written in the main module's go.mod file and will ignore retract directives in go.mod files of dependencies.