Home >Backend Development >Golang >How to Import Specific Package Versions in Go?
Importing Specific Package Versions in Go
In Go, installing a specific version of a package involves following a different approach compared to npm. The go get command does not support versioning out of the box. However, Go 1.11 introduces a new feature called go modules that enables versioned dependency management.
To install a specific version of a package using go modules, follow these steps:
Initialize a module:
go mod init .
Edit the go.mod file to add the dependency with the desired version:
go mod edit -require github.com/wilk/[email protected]@<version>
Refresh dependencies. This may require fetching the module graph and downloading packages:
go get -v -t ./...
Build the application:
go build
Install the compiled binary:
go install
After completing these steps, you can import the specific version of the package in your code:
import ( express "github.com/wilk/[email protected]" )
Go modules provide a convenient way to manage package versions, ensuring that your application uses the correct version of each dependency. For more information on Go modules, refer to the official documentation: https://github.com/golang/go/wiki/Modules.
The above is the detailed content of How to Import Specific Package Versions in Go?. For more information, please follow other related articles on the PHP Chinese website!