Picachieu
Picachieu

Reputation: 3782

equivalent of RubyGems?

I come from a ruby background, and I just started learning go. Is there any standard way to install 3rd-party libraries that's comparable to RubyGems?

Upvotes: 1

Views: 566

Answers (1)

novalagung
novalagung

Reputation: 11502

Since go1.11 released, we have an official go package management tools, the Go Modules.

The difference between go modules and other package management tools is go modules does not rely on $GOPATH. The project must be placed outside of $GOPATH. If your project is already inside a $GOPATH but you wanted to use package management tools, then I suggest to see the old answer below.

Usage:

mkdir testproject
cd testproject

# init project as go module with root package name is testproject
go mod init testproject

# install 3rd party library, it will be stored inside testproject/vendor
go get github.com/labstack/echo
go get github.com/novalagung/gubrak

the go mod init command generates Go.mod file (similar like Gemfile for ruby). You can either install the 3rd party libraries through the usual go get command, or by adding the library metadata into Go.mod file then perform go mod tidy.

More informations about Go Modules: https://blog.golang.org/using-go-modules

Old answer

Go does have package management tool as well, it's called dep.

Usage example:

cd $GOPATH/src
mkdir testproject
cd testproject

# init project
dep init

# install 3rd party library
dep ensure -add github.com/labstack/echo
dep ensure -add github.com/novalagung/gubrak

dep generates Gopkg.toml file (similar like Gemfile for ruby). You can either install the 3rd party libraries through dep ensure -add command, or by adding the library metadata into Gopkg.toml then perform dep ensure.

Btw, there is also few other alternatives other than dep. For more information please take a look at https://github.com/golang/go/wiki/PackageManagementTools.

Upvotes: 2

Related Questions