go get gopkg.in/mgo.v2
The above command in the terminal will install “mgo”, a third-party Go driver package for MongoDB, into your GOPATH, which can be used across the projects put on the GOPATH directory.
After installing the mgo, put the import statement in your programs for reusing the code, as shown below:
import ( "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" )
The MongoDB driver, mgo, provides two packages that we have imported in the above import statement.
go get to install third party packages, it is common for a package to be referenced by its canonical path. That path can also be a path to a public project that is hosted in a code repository such as GitHub.
As such, if you want to import the
flect package, you would use the full canonical path:
$ go get github.com/gobuffalo/flect
go get tool will find the package, on GitHub in this case, and install it into your
For this example the code would be installed in this directory:
Packages are often being updated by the original authors to address bugs or add new features. When this happens, you may want to use the latest version of that package to take advantage of the new features or resolved bug.
To update a package, you can use the
-u flag with the
go get command:
$ go get -u github.com/gobuffalo/flect
This command will also have Go install the package if it is not found locally. If it is already installed, Go will attempt to update the package to the latest version.
go get command always retrieves the latest version of the package available.